|
12 | 12 |
|
13 | 13 | .. dbcommand:: top
|
14 | 14 |
|
15 |
| - :dbcommand:`top` is an administrative command that |
16 |
| - returns usage statistics for each collection. :dbcommand:`top` |
17 |
| - provides amount of time, in microseconds, used and a count of |
18 |
| - operations for the following event types: |
19 |
| - |
20 |
| - - total |
21 |
| - - readLock |
22 |
| - - writeLock |
23 |
| - - queries |
24 |
| - - getmore |
25 |
| - - insert |
26 |
| - - update |
27 |
| - - remove |
28 |
| - - commands |
| 15 | + :dbcommand:`top` is an administrative command that returns usage statistics |
| 16 | + for each collection. You can use :dbcommand:`top` metrics to compare the |
| 17 | + relative performance of your collections against each other. |
29 | 18 |
|
30 | 19 | .. important::
|
31 | 20 |
|
32 | 21 | The :dbcommand:`top` command must be run against a
|
33 | 22 | :doc:`mongod </reference/program/mongod>` instance. Running
|
34 | 23 | :dbcommand:`top` against a :doc:`mongos </reference/program/mongos>`
|
35 |
| - instance will return an error. |
| 24 | + instance returns an error. |
36 | 25 |
|
37 |
| - Issue the :dbcommand:`top` command against the :term:`admin |
38 |
| - database` in the form: |
| 26 | +Definition |
| 27 | +---------- |
| 28 | + |
| 29 | +For every collection, :dbcommand:`top` returns the amount of ``time``, in |
| 30 | +microseconds, that each :ref:`event <event-types>` takes to execute and a |
| 31 | +``count`` of how many times each event has executed. The ``time`` and |
| 32 | +``count`` metrics reset only after you restart your :binary:`~bin.mongod` |
| 33 | +instance. |
39 | 34 |
|
40 |
| - .. code-block:: javascript |
| 35 | +Syntax |
| 36 | +------ |
41 | 37 |
|
42 |
| - { top: 1 } |
43 |
| - |
44 |
| - |
45 |
| -Example |
46 |
| -------- |
47 |
| - |
48 |
| -At the :binary:`~bin.mongo` shell prompt, use :dbcommand:`top` with the |
49 |
| -following invocation: |
| 38 | +Issue the :dbcommand:`top` command against the :term:`admin database`: |
50 | 39 |
|
51 | 40 | .. code-block:: javascript
|
52 | 41 |
|
53 |
| - db.adminCommand("top") |
54 |
| - |
55 |
| -Alternately you can use :dbcommand:`top` as follows: |
| 42 | + db.runCommand( |
| 43 | + { |
| 44 | + top: 1 |
| 45 | + } |
| 46 | + ) |
| 47 | + |
| 48 | +.. _event-types: |
| 49 | + |
| 50 | +Event Fields |
| 51 | +------------ |
| 52 | + |
| 53 | +The :dbcommand:`top` command returns usage statistics for the following event |
| 54 | +fields: |
| 55 | + |
| 56 | +.. list-table:: |
| 57 | + :header-rows: 1 |
| 58 | + :widths: 20 80 |
| 59 | + |
| 60 | + * - Field |
| 61 | + - Description |
| 62 | + |
| 63 | + * - ``total`` |
| 64 | + - The combination of all ``readLock`` and ``writeLock`` operations. |
| 65 | + |
| 66 | + * - ``readLock`` |
| 67 | + - Usage statistics for operations that use read locks. These operations |
| 68 | + include but are not limited to queries and aggregations. |
| 69 | + |
| 70 | + * - ``writeLock`` |
| 71 | + - Usage statistics for operations that use write locks. These operations |
| 72 | + include but are not limited to inserting, updating, and removing |
| 73 | + documents. |
| 74 | + |
| 75 | + * - ``queries`` |
| 76 | + - Usage statistics for query operations such as :dbcommand:`find`. The |
| 77 | + ``queries.time`` and ``queries.count`` fields also update |
| 78 | + ``readLock.time`` and increment ``readLock.count``. |
| 79 | + |
| 80 | + * - ``getmore`` |
| 81 | + - Usage statistics for :dbcommand:`getMore` operations. The |
| 82 | + ``getmore.time`` and ``getmore.count`` fields also update |
| 83 | + ``readLock.time`` and increment ``readLock.count``. |
| 84 | + |
| 85 | + * - ``insert`` |
| 86 | + - Usage statistics for :dbcommand:`insert` operations. The |
| 87 | + ``insert.time`` and ``insert.count`` fields also update |
| 88 | + ``readLock.time`` and increment ``readLock.count``. |
| 89 | + |
| 90 | + * - ``update`` |
| 91 | + - Usage statistics for :dbcommand:`update` operations. The |
| 92 | + ``update.time`` and ``update.count`` fields also update |
| 93 | + ``readLock.time`` and increment ``readLock.count``. |
| 94 | + |
| 95 | + * - ``remove`` |
| 96 | + - Usage statistics for :dbcommand:`delete` operations. The |
| 97 | + ``remove.time`` and ``remove.count`` fields also update |
| 98 | + ``readLock.time`` and increment ``readLock.count``. |
| 99 | + |
| 100 | + * - ``commands`` |
| 101 | + - Usage statistics for operations such as aggregations, index creation, |
| 102 | + and index removal. Depending on the type of command, the |
| 103 | + ``commands.time`` and ``commands.count`` fields update the ``writeLock`` |
| 104 | + fields or the ``readLock`` fields. |
| 105 | + |
| 106 | + For example, aggregation operations increment ``readLock.time`` and |
| 107 | + ``readLock.count``. Index creation increments ``writeLock.time`` |
| 108 | + and ``writeLock.count``. |
56 | 109 |
|
57 |
| -.. code-block:: javascript |
58 |
| - |
59 |
| - db.adminCommand( { top: 1 } ) |
| 110 | +Example |
| 111 | +------- |
60 | 112 |
|
61 |
| -The output of the top command would resemble the following |
62 |
| -output: |
| 113 | +The output of the :dbcommand:`top` command resembles the following output: |
63 | 114 |
|
64 | 115 | .. code-block:: javascript
|
65 | 116 |
|
66 | 117 | {
|
67 | 118 | "totals" : {
|
| 119 | + note: "all times in microseconds", |
68 | 120 | "records.users" : {
|
69 | 121 | "total" : {
|
70 | 122 | "time" : 305277,
|
@@ -104,3 +156,8 @@ output:
|
104 | 156 | }
|
105 | 157 | }
|
106 | 158 | }
|
| 159 | + |
| 160 | +Learn More |
| 161 | +---------- |
| 162 | + |
| 163 | +- :ref:`faq-concurrency-locking` |
0 commit comments