Skip to content

Commit 23b7b5d

Browse files
jason-price-mongodbjason-price-mongodb
andauthored
DOCSP-27565-database-profiler-update (#5824) (#5923)
* DOCSP-27565-database-profiler-update * DOCSP-27565-database-profiler-update * DOCSP-27565-database-profiler-update * DOCSP-27565-database-profiler-update * DOCSP-27565-database-profiler-update * DOCSP-27565-database-profiler-update * DOCSP-27565-database-profiler-update --------- Co-authored-by: jason-price-mongodb <jshfjghsdfgjsdjh@aolsdjfhkjsdhfkjsdf.com>
1 parent 655f4d8 commit 23b7b5d

File tree

1 file changed

+84
-71
lines changed

1 file changed

+84
-71
lines changed

source/tutorial/manage-the-database-profiler.txt

Lines changed: 84 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ The database profiler collects detailed information about
1616
:ref:`database-commands` executed against a running :binary:`~bin.mongod`
1717
instance. This includes CRUD operations as well as configuration and
1818
administration commands.
19+
1920
The profiler writes all the data it collects to a
2021
:data:`system.profile <<database>.system.profile>` collection, a
2122
:doc:`capped collection </core/capped-collections>` in each profiled
@@ -30,8 +31,8 @@ levels <database-profiling-level>`.
3031
When enabled, profiling has an effect on database performance and
3132
disk use. See :ref:`Database Profiler Overhead<database-profiling-overhead>` for more information.
3233

33-
This document outlines a number of key administration options for the
34-
database profiler. For additional related information, see:
34+
This page shows important administration options for the
35+
database profiler. For additional information, see:
3536

3637
- :ref:`profiler`
3738
- :ref:`Profile Command <profile-command>`
@@ -56,31 +57,32 @@ Enable and Configure Database Profiling
5657

5758
You can enable database profiling for :binary:`~bin.mongod` instances.
5859

59-
This section uses :binary:`~bin.mongosh` helper
60-
:method:`db.setProfilingLevel()` helper to enable profiling. For
61-
instructions using the driver, see your :driver:`driver
62-
documentation </>`.
60+
This section shows how you use the :binary:`~bin.mongosh` helper method
61+
:method:`db.setProfilingLevel()` to enable profiling. To use a driver
62+
method instead, see the :driver:`driver documentation`.
6363

64-
When you enable profiling for a :binary:`~bin.mongod` instance, you set
64+
To enable profiling for a :binary:`~bin.mongod` instance, set
6565
the :ref:`profiling level <database-profiling-levels>` to a value
66-
greater than 0. The profiler records data in the :data:`system.profile
66+
greater than ``0``. The profiler records data in the :data:`system.profile
6767
<<database>.system.profile>` collection. MongoDB creates the
6868
:data:`system.profile <<database>.system.profile>` collection in a
6969
database after you enable profiling for that database.
7070

7171
To enable profiling and set the profiling level, pass the profiling
7272
level to the :method:`db.setProfilingLevel()` helper. For example, to
73-
enable profiling for all database operations, consider the following
74-
operation in :binary:`~bin.mongosh`:
73+
enable profiling for all database operations for the currently connected
74+
database, run this operation in :binary:`~bin.mongosh`:
7575

7676
.. code-block:: javascript
7777

7878
db.setProfilingLevel(2)
7979

80-
The shell returns a document showing the *previous* level of profiling.
81-
The ``"ok" : 1`` key-value pair indicates the operation succeeded:
80+
The shell returns the *previous* profiling level in the ``was`` field
81+
and sets the new level. In the following output, the ``"ok" :
82+
1`` key-value pair indicates the operation succeeded:
8283

8384
.. code-block:: javascript
85+
:copyable: false
8486

8587
{ "was" : 0, "slowms" : 100, "sampleRate" : 1.0, "ok" : 1 }
8688

@@ -97,7 +99,7 @@ The :ref:`slowms <set-profiling-level-options-slowms>` and
9799
settings are *global*. When set, these settings affect all databases in
98100
your process.
99101

100-
When set via the :dbcommand:`profile` command or
102+
When set through the :dbcommand:`profile` command or
101103
:method:`db.setProfilingLevel()` shell helper method, :ref:`profiling
102104
level <database-profiling-level>` and :ref:`filter
103105
<set-profiling-level-options-filter>` settings are set at the *database*
@@ -111,7 +113,7 @@ Specify the Threshold for Slow Operations
111113
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
112114

113115
By default, the slow operation threshold is 100 milliseconds. To change
114-
the slow operation threshold, specify the desired threshold value in
116+
the slow operation threshold, specify the required threshold value in
115117
one of the following ways:
116118

117119
- Set the value of ``slowms`` using the :dbcommand:`profile` command or
@@ -122,37 +124,38 @@ one of the following ways:
122124
- Set the value of :setting:`~operationProfiling.slowOpThresholdMs` in a
123125
:ref:`configuration file <configuration-options>`.
124126

125-
For example, the following code sets the profiling level for the
126-
current :binary:`~bin.mongod` instance to ``1`` and sets the slow
127-
operation threshold for the :binary:`~bin.mongod` instance to 20
127+
The following example sets the profiling level for the
128+
currently connected database to ``1`` and sets the slow
129+
operation threshold for the :binary:`~bin.mongod` instance to ``20``
128130
milliseconds:
129131

130132
.. code-block:: javascript
131133

132-
db.setProfilingLevel(1, { slowms: 20 })
134+
db.setProfilingLevel( 1, { slowms: 20 } )
133135

134-
Profiling level of ``1`` will profile operations slower than the
135-
threshold.
136+
A profiling level of ``1`` causes the profiler to record operations
137+
slower than the ``slowms`` threshold.
136138

137139
.. important::
140+
138141
The slow operation threshold applies to all databases in a
139142
:binary:`~bin.mongod` instance. It is used by both the database profiler
140143
and the diagnostic log and should be set to the highest useful value to
141144
avoid performance degradation.
142145

143-
Starting in MongoDB 4.0, you can use :method:`db.setProfilingLevel()`
146+
You can use :method:`db.setProfilingLevel()`
144147
to configure ``slowms`` and ``sampleRate`` for :binary:`~bin.mongos`.
145148
For the :binary:`~bin.mongos`, the ``slowms`` and ``sampleRate``
146149
configuration settings only affect the diagnostic log and not the
147150
profiler since profiling is not available on :binary:`~bin.mongos`.
148151
[#mongos-systemlog]_
149152

150-
For example, the following sets a :binary:`~bin.mongos` instance's slow
151-
operation threshold for logging slow operations:
153+
The following example sets a :binary:`~bin.mongos` instance's slow
154+
operation threshold for logging slow operations to ``20``:
152155

153156
.. code-block:: javascript
154157

155-
db.setProfilingLevel(0, { slowms: 20 })
158+
db.setProfilingLevel( 0, { slowms: 20 } )
156159

157160
.. include:: /includes/extracts/4.2-changes-log-query-shapes-plan-cache-key.rst
158161

@@ -161,7 +164,7 @@ operation threshold for logging slow operations:
161164
Profile a Random Sample of Slow Operations
162165
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
163166

164-
To profile only a randomly sampled subset of all *slow* operations ,
167+
To profile only a randomly sampled subset of all *slow* operations,
165168
specify the desired sample rate in one of the following ways:
166169
[#slow-oplogs]_
167170

@@ -176,33 +179,33 @@ specify the desired sample rate in one of the following ways:
176179
:ref:`configuration file <configuration-options>`.
177180

178181
By default, ``sampleRate`` is set to ``1.0``, meaning all *slow*
179-
operations are profiled. When ``sampleRate`` is set between 0 and 1,
180-
databases with profiling level ``1`` will only profile a randomly sampled
181-
percentage of *slow* operations according to ``sampleRate``.
182+
operations are profiled. When ``sampleRate`` is set between ``0`` and ``1``,
183+
databases with a profiling level ``1`` only profile a randomly sampled
184+
percentage of *slow* operations based on ``sampleRate``.
182185

183-
For example, the following method sets the profiling level for the
184-
:binary:`~bin.mongod` to ``1`` and sets the profiler to sample 42% of
185-
all *slow* operations:
186+
The following example sets the profiling level for the currently
187+
connected database to ``1`` and sets the profiler to sample 42% of all
188+
*slow* operations:
186189

187190
.. code-block:: javascript
188191

189-
db.setProfilingLevel(1, { sampleRate: 0.42 })
192+
db.setProfilingLevel( 1, { sampleRate: 0.42 } )
190193

191194
The modified sample rate value also applies to the system log.
192195

193-
Starting in MongoDB 4.0, you can use :method:`db.setProfilingLevel()`
196+
You can use :method:`db.setProfilingLevel()`
194197
to configure ``slowms`` and ``sampleRate`` for :binary:`~bin.mongos`.
195198
For the :binary:`~bin.mongos`, the ``slowms`` and
196199
``sampleRate`` configuration settings only affect the diagnostic log
197-
and not the profiler since profiling is not available on
200+
and not the profiler because profiling isn't available on
198201
:binary:`~bin.mongos`. [#mongos-systemlog]_
199202

200203
For example, the following sets a :binary:`~bin.mongos` instance's
201204
sampling rate for logging slow operations:
202205

203206
.. code-block:: javascript
204207

205-
db.setProfilingLevel(0, { sampleRate: 0.42 })
208+
db.setProfilingLevel( 0, { sampleRate: 0.42 } )
206209

207210
.. important::
208211

@@ -221,7 +224,7 @@ You can set a filter to control which operations are profiled and
221224
logged. You can set the profiling filter in one of the following ways:
222225

223226
- Set the value of ``filter`` using the :dbcommand:`profile` command
224-
or :method:`db.setProfilingLevel()` shell helper method.
227+
or the :method:`db.setProfilingLevel()` shell helper method.
225228

226229
- Set the value of :setting:`~operationProfiling.filter` in a
227230
:ref:`configuration file <configuration-options>`.
@@ -240,8 +243,8 @@ available on :binary:`~bin.mongos`.
240243
<set-profiling-level-options-sampleRate>` options do not affect the
241244
diagnostic log or the profiler.
242245

243-
For example, the following :method:`db.setProfilingLevel()` method sets
244-
for a :binary:`~bin.mongod` instance:
246+
The following :method:`db.setProfilingLevel()` example sets
247+
the profile level for the currently connected database:
245248

246249
- the :ref:`profiling level <set-profiling-level-level>` to ``2``,
247250

@@ -259,8 +262,8 @@ for a :binary:`~bin.mongod` instance:
259262
Check Profiling Level
260263
~~~~~~~~~~~~~~~~~~~~~
261264

262-
To view the :ref:`profiling level <database-profiling-levels>`, issue
263-
the following from :binary:`~bin.mongosh`:
265+
To view the :ref:`profiling level <database-profiling-levels>`, run
266+
the following example in :binary:`~bin.mongosh`:
264267

265268
.. code-block:: javascript
266269

@@ -283,17 +286,23 @@ that should be profiled.
283286
Disable Profiling
284287
~~~~~~~~~~~~~~~~~
285288

286-
To disable profiling, use the following helper in
289+
To disable profiling, run the following example in
287290
:binary:`~bin.mongosh`:
288291

289292
.. code-block:: javascript
290293

291294
db.setProfilingLevel(0)
292295

296+
.. note::
297+
298+
Disabling profiling can improve database performance and lower disk
299+
use. For more information, see :ref:`Database Profiler
300+
Overhead<database-profiling-overhead>` .
301+
293302
Enable Profiling for an Entire ``mongod`` Instance
294303
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
295304

296-
For development purposes in testing environments, you can enable
305+
For development and test environments, you can enable
297306
database profiling for an entire :binary:`~bin.mongod` instance. The
298307
profiling level applies to all databases provided by the
299308
:binary:`~bin.mongod` instance.
@@ -313,10 +322,10 @@ This sets the profiling level to ``1``, defines slow operations as those
313322
that last longer than ``15`` milliseconds, and specifies that only 50%
314323
of *slow* operations should be profiled. [#slow-oplogs]_
315324

316-
The ``slowms`` and ``slowOpSampleRate`` also affect which operations
317-
are recorded to the diagnostic log when :parameter:`logLevel` is
318-
set to ``0``. The ``slowms`` and ``slowOpSampleRate`` are also
319-
available to configure diagnostic logging for :binary:`~bin.mongos`. [#slow-oplogs]_
325+
The ``slowms`` and ``slowOpSampleRate`` also affect the operations that
326+
are recorded in the diagnostic log when :parameter:`logLevel` is set to
327+
``0``. The ``slowms`` and ``slowOpSampleRate`` are also available to
328+
configure diagnostic logging for :binary:`~bin.mongos`. [#slow-oplogs]_
320329

321330
.. seealso::
322331

@@ -365,8 +374,8 @@ operation, including reads, on the :data:`system.profile
365374
Example Profiler Data Queries
366375
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
367376

368-
This section displays example queries to the :data:`system.profile <<database>.system.profile>`
369-
collection. For an explanation of the query output, see
377+
This section shows example queries on the :data:`system.profile
378+
<<database>.system.profile>` collection. For query output details, see
370379
:doc:`/reference/database-profiler`.
371380

372381
To return the most recent 10 log entries in the :data:`system.profile <<database>.system.profile>`
@@ -391,45 +400,44 @@ the following. This example returns operations in the ``mydb`` database's
391400

392401
db.system.profile.find( { ns : 'mydb.test' } ).pretty()
393402

394-
To return operations slower than ``5`` milliseconds, run a query
395-
similar to the following:
403+
To return operations that take longer than 5 milliseconds to complete,
404+
run:
396405

397406
.. code-block:: javascript
398407

399408
db.system.profile.find( { millis : { $gt : 5 } } ).pretty()
400409

401-
To return information from a certain time range, run a query similar to
402-
the following:
410+
To return operations for a specific time range, run:
403411

404412
.. code-block:: javascript
405413

406-
db.system.profile.find({
407-
ts : {
408-
$gt: new ISODate("2012-12-09T03:00:00Z"),
409-
$lt: new ISODate("2012-12-09T03:40:00Z")
410-
}
411-
}).pretty()
414+
db.system.profile.find( {
415+
ts : {
416+
$gt: new ISODate("2012-12-09T03:00:00Z"),
417+
$lt: new ISODate("2012-12-09T03:40:00Z")
418+
}
419+
} ).pretty()
412420

413421
The following example looks at the time range, suppresses the ``user``
414422
field from the output to make it easier to read, and sorts the results
415423
by how long each operation took to run:
416424

417425
.. code-block:: javascript
418426

419-
db.system.profile.find({
420-
ts : {
421-
$gt: new ISODate("2011-07-12T03:00:00Z"),
422-
$lt: new ISODate("2011-07-12T03:40:00Z")
423-
}
424-
}, { user: 0 }).sort( { millis: -1 } )
427+
db.system.profile.find( {
428+
ts : {
429+
$gt: new ISODate("2011-07-12T03:00:00Z"),
430+
$lt: new ISODate("2011-07-12T03:40:00Z")
431+
}
432+
}, { user: 0 } ).sort( { millis: -1 } )
425433

426434
Show the Five Most Recent Events
427435
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
428436

429437
On a database that has profiling enabled, the ``show profile`` helper
430438
in :binary:`~bin.mongosh` displays the 5 most recent operations
431-
that took at least 1 millisecond to execute. Issue ``show profile``
432-
from :binary:`~bin.mongosh`, as follows:
439+
that took at least 1 millisecond to execute. Run ``show profile``
440+
from :binary:`~bin.mongosh`:
433441

434442
.. code-block:: javascript
435443

@@ -444,11 +452,16 @@ When enabled, profiling has an effect on database performance,
444452
especially when configured with a
445453
:ref:`profiling level<database-profiling-level>` of 2, or when using a
446454
low :ref:`threshold<database-profiling-specify-slowms-threshold>` value
447-
with a profiling level of 1. Profiling also consumes disk space, as it
448-
logs to both the :data:`system.profile <<database>.system.profile>`
449-
collection and also the MongoDB :option:`logfile <mongod --logpath>`.
450-
Carefully consider any performance and security implications before
451-
configuring and enabling the profiler on a production deployment.
455+
with a profiling level of 1.
456+
457+
Profiling also uses disk space, because profiling
458+
writes logs to the :data:`system.profile <<database>.system.profile>`
459+
collection and the MongoDB :option:`logfile <mongod --logpath>`.
460+
461+
.. warning::
462+
463+
Consider performance and storage implications before
464+
you enable the profiler in a production deployment.
452465

453466
The ``system.profile`` Collection
454467
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)