Skip to content

Commit 1319fa9

Browse files
committed
DOCS-10546: random sampling for profiler/logging
1 parent f042e12 commit 1319fa9

15 files changed

+436
-293
lines changed

source/administration/analyzing-mongodb-performance.txt

Lines changed: 15 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -179,74 +179,29 @@ information.
179179
Database Profiling
180180
------------------
181181

182-
MongoDB's "Profiler" is a database profiling system that can help identify
183-
inefficient queries and operations.
182+
The :doc:`/tutorial/manage-the-database-profiler` collects detailed
183+
information about operations run against a mongod instance. The
184+
profiler's output can help to identify inefficient queries and
185+
operations.
184186

185-
The following profiling levels are available:
186-
187-
.. list-table::
188-
:header-rows: 1
189-
190-
* - **Level**
191-
192-
- **Setting**
193-
194-
* - 0
195-
196-
- Off. No profiling
197-
198-
* - 1
199-
200-
- On. Only includes *"slow"* operations
201-
202-
* - 2
203-
204-
- On. Includes *all* operations
187+
You can enable and configure profiling for individual databases or for
188+
all databases on a :program:`mongod` instance.
189+
Profiler settings affect only a single :program:`mongod` instance and
190+
will not propagate across a :term:`replica set` or :term:`sharded
191+
cluster`.
205192

206-
Enable the profiler by setting the
207-
:dbcommand:`profile` value using the following command in the
208-
:program:`mongo` shell:
193+
See :doc:`/tutorial/manage-the-database-profiler` for information on
194+
enabling and configuring the profiler.
209195

210-
.. code-block:: javascript
211-
212-
db.setProfilingLevel(1)
213-
214-
The :setting:`~operationProfiling.slowOpThresholdMs` setting defines what constitutes a "slow"
215-
operation. To set the threshold above which the profiler considers
216-
operations "slow" (and thus, included in the level ``1`` profiling
217-
data), you can configure :setting:`~operationProfiling.slowOpThresholdMs` at runtime as an argument to
218-
the :method:`db.setProfilingLevel()` operation.
196+
The following profiling levels are available:
219197

220-
.. see:: The documentation of :method:`db.setProfilingLevel()` for more
221-
information.
198+
.. include:: /includes/database-profiler-levels.rst
222199

223-
By default, :program:`mongod` records all "slow" queries to its
224-
:setting:`log <logpath>`, as defined by :setting:`~operationProfiling.slowOpThresholdMs`.
200+
.. include:: /includes/warning-profiler-performance.rst
225201

226202
.. note::
203+
.. include:: /includes/fact-log-slow-queries.rst
227204

228-
Because the database profiler can negatively impact
229-
performance, only enable profiling for strategic intervals and as
230-
minimally as possible on production systems.
231-
232-
You may enable profiling on a per-:program:`mongod` basis. This
233-
setting will not propagate across a :term:`replica set` or
234-
:term:`sharded cluster`.
235-
236-
You can view the output of the profiler in the ``system.profile``
237-
collection of your database by issuing the ``show profile`` command in
238-
the :program:`mongo` shell, or with the following operation:
239-
240-
.. code-block:: javascript
241-
242-
db.system.profile.find( { millis : { $gt : 100 } } )
243-
244-
This returns all operations that lasted longer than 100 milliseconds.
245-
Ensure that the value specified here (``100``, in this example) is above the
246-
:setting:`~operationProfiling.slowOpThresholdMs` threshold.
247-
248-
You must use the :operator:`$query` operator to access the ``query``
249-
field of documents within ``system.profile``.
250205

251206
.. class:: hidden
252207

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
position: 1
2+
name: profile
3+
type: int
4+
optional: false
5+
description: |
6+
Default: 0
7+
8+
| Specifies which operations should be profiled.
9+
| The following profiler levels are available:
10+
11+
.. list-table::
12+
:header-rows: 1
13+
:widths: 25 75
14+
15+
* - Level
16+
- Description
17+
18+
* - ``-1``
19+
- Returns the current profiler level, but does not change it.
20+
21+
* - ``0``
22+
- Turns the profiler off so that it does not
23+
collect any data.
24+
This is the default profiler level.
25+
26+
* - ``1``
27+
- Sets the profiler to collect data for operations that take
28+
longer than the value of ``slowms``.
29+
30+
* - ``2``
31+
- Sets the profiler to collect data for all operations.
32+
33+
interface: dbcommand
34+
operation: profile
35+
arg_name: field
36+
---
37+
position: 2
38+
name: slowms
39+
type: int
40+
optional: true
41+
description: |
42+
Default: 100
43+
44+
.. include:: /includes/dbcommand-slowms-definition.rst
45+
46+
.. note::
47+
This argument affects the same setting as the configuration option
48+
:setting:`~operationProfiling.slowOpThresholdMs`.
49+
50+
51+
interface: dbcommand
52+
operation: profile
53+
arg_name: field
54+
---
55+
position: 3
56+
name: sampleRate
57+
type: double
58+
optional: true
59+
description: |
60+
Default: 1.0
61+
62+
| The fraction of *slow* operations that should be profiled.
63+
| ``sampleRate`` accepts values between 0 and 1, inclusive.
64+
65+
.. note::
66+
This argument affects the same setting as the configuration option
67+
:setting:`~operationProfiling.slowOpSampleRate`.
68+
69+
.. versionadded:: 3.6
70+
interface: dbcommand
71+
operation: profile
72+
arg_name: field
73+
...
Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
arg_name: param
2-
description: |-
3-
Specifies a profiling level, which is either ``0`` for no profiling, ``1`` for only slow operations, or ``2`` for all operations.
2+
description: |
3+
Configures the profiler level.
4+
The following profiler levels are available:
5+
6+
.. include:: /includes/database-profiler-levels.rst
7+
48
interface: method
59
name: level
610
operation: db.setProfilingLevel
@@ -9,12 +13,41 @@ position: 1
913
type: integer
1014
---
1115
arg_name: param
12-
description: |-
13-
Sets the threshold in milliseconds for the profile to consider a query or operation to be slow.
16+
description: |
17+
Accepts an integer or an options document. If an integer value is
18+
passed as the ``options`` argument instead of a document, the value is
19+
assigned to ``slowms``.
20+
The following options are available:
21+
22+
.. list-table::
23+
:stub-columns: 1
24+
:widths: 15 85
25+
26+
* - slowms
27+
- | Default: 100
28+
| Type: integer
29+
30+
.. include:: /includes/dbcommand-slowms-definition.rst
31+
32+
.. note::
33+
This argument affects the same setting as the configuration
34+
file option :setting:`~operationProfiling.slowOpThresholdMs`.
35+
36+
* - sampleRate
37+
- | Default: 1.0
38+
| Type: double
39+
40+
The fraction of *slow* operations that should be profiled.
41+
``sampleRate`` accepts values between 0 and 1, inclusive.
42+
43+
.. note::
44+
This argument affects the same setting as the configuration option
45+
:setting:`~operationProfiling.slowOpSampleRate`.
46+
1447
interface: method
15-
name: slowms
48+
name: options
1649
operation: db.setProfilingLevel
1750
optional: true
1851
position: 2
19-
type: integer
52+
type: document or integer
2053
...
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.. list-table::
2+
:header-rows: 1
3+
:widths: 25 75
4+
5+
* - Level
6+
- Description
7+
8+
* - ``0``
9+
- The profiler is off and does not collect any data.
10+
This is the default profiler level.
11+
12+
* - ``1``
13+
- The profiler collects data for operations that take longer
14+
than the value of ``slowms``.
15+
16+
* - ``2``
17+
- The profiler collects data for all operations.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
The *slow* operation time threshold, in milliseconds. Operations
2+
that run for longer than this threshold are considered *slow*.
3+
4+
.. include:: /includes/fact-log-slow-queries.rst
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
The system log and profiler are configured separately but share the same
2+
settings for ``slowms`` and ``sampleRate``.
3+
When :setting:`~param.logLevel` is set to ``0``, :program:`mongod`
4+
records *slow* queries to the system log at a rate determined by
5+
:setting:`~operationProfiling.slowOpSampleRate`. At higher
6+
:setting:`~param.logLevel` settings, all queries appear in the system
7+
log regardless of their latency.

source/includes/options-conf.yaml

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,6 +1010,37 @@ description: |
10101010
method.
10111011
---
10121012
program: conf
1013+
name: operationProfiling.mode
1014+
type: string
1015+
default: "``off``"
1016+
directive: setting
1017+
description: |
1018+
Specifies which operations should be :doc:`profiled
1019+
</tutorial/manage-the-database-profiler>`.
1020+
The following profiler levels are available:
1021+
1022+
.. list-table::
1023+
:header-rows: 1
1024+
:widths: 25 75
1025+
1026+
* - Level
1027+
- Description
1028+
1029+
* - ``off``
1030+
- The profiler is off and does not collect any data.
1031+
This is the default profiler level.
1032+
1033+
* - ``slowOp``
1034+
- The profiler collects data for operations that take longer
1035+
than the value of ``slowms``.
1036+
1037+
* - ``all``
1038+
- The profiler collects data for all operations.
1039+
1040+
.. include:: /includes/warning-profiler-performance.rst
1041+
1042+
---
1043+
program: conf
10131044
name: operationProfiling.slowOpThresholdMs
10141045
type: integer
10151046
default: 100
@@ -1024,18 +1055,32 @@ post: |
10241055
The {{role}} setting is available only for :program:`mongod`.
10251056
---
10261057
program: conf
1027-
name: operationProfiling.mode
1058+
name: operationProfiling.slowOpSampleRate
1059+
type: double
1060+
default: 1.0
1061+
directive: setting
1062+
replacement:
1063+
program: ":program:`mongod`"
1064+
inherit:
1065+
name: slowOpSampleRate
1066+
program: mongod
1067+
file: options-mongod.yaml
1068+
---
1069+
program: conf
1070+
name: storage.dbPath
10281071
type: string
10291072
directive: setting
10301073
replacement:
10311074
program: ":program:`mongod`"
1032-
intro: "The"
1075+
storage_engine: :setting:`~storage.engine`
10331076
inherit:
1034-
name: profilingmode
1077+
name: dbpath
10351078
program: mongod
10361079
file: options-mongod.yaml
10371080
post: |
10381081
The {{role}} setting is available only for :program:`mongod`.
1082+
1083+
.. include:: /includes/extracts/linux-config-expectations-storage-dbpath.rst
10391084
---
10401085
program: conf
10411086
name: storage.dbPath

0 commit comments

Comments
 (0)