Database Reference
In-Depth Information
The MongoDB Profiler
The MongoDB profiler is a tool that records statistical information and execution plan details for every query that
meets the trigger criteria. You can enable this tool separately on each database or for all databases by using the
--profile and --slowms options to start your MongoD process (more on what these values mean shortly). These
options can also be added to your mongodb.conf file, if that is how you are starting your MongoD process.
Once the profiler is enabled, MongoDB inserts a document with information about the performance and
execution details of each query submitted by your application into a special capped collection called system.profile .
You can use this collection to inspect the details of each query logged using standard collection querying commands.
The system.profile collection is limited to a maximum of 1024KB of data, so that the profiler will not fill the
disk with logging information. This limit should be enough to capture a few thousand profiles of even the most
complex queries.
When the profiler is enabled, it will impact the performance of your server, so it is not a good idea to leave
it running on a production server unless you are performing an analysis for some observed issue. Don't be tempted to
leave it running permanently to provide a window on recently executed queries.
Warning
Enabling and Disabling the DB Profiler
It's a simple matter to turn on the MongoDB profiler:
$mongo
>use blog
>db.setProfilingLevel(1)
It is an equally simple matter to disable the profiler:
$mongo
>use blog
>db.setProfilingLevel(0)
MongoDB can also enable the profiler only for queries that exceed a specified execution time. The following
example logs only queries that take more than half a second to execute:
$mongo
>use blog
>db.setProfilingLevel(1,500)
As shown here, for profiling level 1, you can supply a maximum query execution time value in milliseconds (ms).
If the query runs for longer than this amount of time, it is profiled and logged; otherwise, it is ignored. This provides
the same functionality seen in MySQL's slow query log.
Finally, you can enable profiling for all queries by setting the profiler level to 2.
$mongo
>use blog
>db.setProfilingLevel(2)
 
 
Search WWH ::




Custom Search