db.collection.latencyStats()

Definition

  • db.collection.latencyStats(options)

mongo Shell Method

This page documents the mongo shell method, and doesnot refer to the MongoDB Node.js driver (or any other driver)method. For corresponding MongoDB driver API, refer to your specificMongoDB driver documentation instead.

db.collection.latencyStats() returns latencystatistics for a given collection. It is a wrapper around$collStats.

This method has the form:

  1. db.collection.latencyStats( { histograms: <boolean> } )

The histograms argument is an optional boolean. Ifhistograms: true then latencyStats() addslatency histograms to the return document.

See also

$collStats

Output

latencyStats() returns a document containinga field latencyStats, containing the following fields:

Field NameDescription
readsLatency statistics for read requests.
writesLatency statistics for write requests.
commandsLatency statistics for database commands.

Each of these fields contains an embedded document bearing thefollowing fields:

Field NameDescription
latencyA 64-bit integer giving the total combinedlatency in microseconds.
opsA 64-bit integer giving the total number ofoperations performed on the collection since startup.
histogramAn array of embedded documents, each representing a latency range.Each document covers twice the previous document’s range. Forupper values between 2048 microseconds and roughly 1 second,the histogram includes half-steps.This field only exists given thelatencyStats: { histograms: true } option. Empty ranges witha zero count are omitted from the output.Each document bears the following fields:
Field NameDescription
microsA 64-bit integer giving the inclusiveupper time bound of the current latency range inmicroseconds.The document’s range spans between the previous document’smicros value, exclusive, and this document’smicros value, inclusive.
countA 64-bit integer giving the number ofoperations with latency less than or equal to micros.

For example, if collStats returns the following histogram:

  1. histogram: [
  2. { micros: NumberLong(1), count: NumberLong(10) },
  3. { micros: NumberLong(2), count: NumberLong(1) },
  4. { micros: NumberLong(4096), count: NumberLong(1) },
  5. { micros: NumberLong(16384), count: NumberLong(1000) },
  6. { micros: NumberLong(49152), count: NumberLong(100) }
  7. ]

This indicates that there were:

  • 10 operations taking 1 microsecond or less,
  • 1 operation in the range (1, 2] microseconds,
  • 1 operation in the range (3072, 4096] microseconds,
  • 1000 operations in the range (12288, 16384], and
  • 100 operations in the range (32768, 49152].

Examples

You can run latencyStats() in a mongoshell as follows:

  1. db.data.latencyStats( { histograms: true } ).pretty()

latencyStats() returns a document such asthe following:

  1. {
  2. "ns" : "test.data",
  3. "localTime" : ISODate("2016-11-01T21:56:28.962Z"),
  4. "latencyStats" : {
  5. "reads" : {
  6. "histogram" : [
  7. {
  8. "micros" : NumberLong(16),
  9. "count" : NumberLong(6)
  10. },
  11. {
  12. "micros" : NumberLong(512),
  13. "count" : NumberLong(1)
  14. }
  15. ],
  16. "latency" : NumberLong(747),
  17. "ops" : NumberLong(7)
  18. },
  19. "writes" : {
  20. "histogram" : [
  21. {
  22. "micros" : NumberLong(64),
  23. "count" : NumberLong(1)
  24. },
  25. {
  26. "micros" : NumberLong(24576),
  27. "count" : NumberLong(1)
  28. }
  29. ],
  30. "latency" : NumberLong(26845),
  31. "ops" : NumberLong(2)
  32. },
  33. "commands" : {
  34. "histogram" : [ ],
  35. "latency" : NumberLong(0),
  36. "ops" : NumberLong(0)
  37. }
  38. }
  39. }