db.collection.latencyStats()

On this page本页内容

Definition定义

db.collection.latencyStats(options)
Important重要
mongosh Method

This is a mongosh method. This is not the documentation for Node.js or other programming language specific driver methods.

In most cases, mongosh methods work the same way as the legacy mongo shell methods. However, some legacy methods are unavailable in mongosh.

For the legacy mongo shell documentation, refer to the documentation for the corresponding MongoDB Server release:

For MongoDB API drivers, refer to the language specific MongoDB driver documentation.

db.collection.latencyStats() returns latency statistics for a given collection. 返回给定集合的延迟统计信息。It is a wrapper around $collStats.它是$collStats的包装。

This method has the form:此方法具有以下形式:

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

The histograms argument is an optional boolean. histograms参数是可选的布尔值。If histograms: true then latencyStats() adds latency histograms to the return document.如果histograms: true,则latencyStats()将延迟直方图添加到返回文档中。

Tip提示
See also: 参阅:

Output输出

latencyStats() returns a document containing a field latencyStats, containing the following fields:返回包含字段latencyStats的文档,该字段包含以下字段:

Field Name字段名Description描述
readsLatency statistics for read requests.读取请求的延迟统计信息。
writesLatency statistics for write requests.写入请求的延迟统计信息。
commandsLatency statistics for database commands.数据库命令的延迟统计信息。

Each of these fields contains an embedded document bearing the following fields:每个字段都包含一个嵌入文档,其中包含以下字段:

Field Name字段名称Description描述
latencyA 64-bit integer giving the total combined latency in microseconds. 一个64位整数,以微秒为单位给出总的组合延迟。
opsA 64-bit integer giving the total number of operations performed on the collection since startup. 一个64位整数,给出自启动以来对集合执行的操作总数。
histogram

An array of embedded documents, each representing a latency range. 嵌入文档的数组,每个表示一个延迟范围。Each document covers twice the previous document's range. 每个文档覆盖的范围是前一个文档的两倍。For upper values between 2048 microseconds and roughly 1 second, the histogram includes half-steps.对于2048微秒到大约1秒之间的上限值,直方图包括半步。

This field only exists given the latencyStats: { histograms: true } option. 此字段仅在给定latencyStats: { histograms: true }选项时存在。Empty ranges with a zero count are omitted from the output.输出中将省略计数为零的空范围。

Each document bears the following fields:每个文档都包含以下字段:

Field Name字段名称Description描述
micros

A 64-bit integer giving the inclusive upper time bound of the current latency range in microseconds.一个64位整数,以微秒为单位给出当前延迟范围的包含上限。

The document's range spans between the previous document's micros value, exclusive, and this document's micros value, inclusive.文档的范围介于前一个文档的micro值(不包括在内)和此文档的micros值(包括在内)之间。

countA 64-bit integer giving the number of operations with latency less than or equal to micros. 一个64位整数,给出延迟小于或等于micros的操作数。

For example, if collStats returns the following histogram:例如,如果collStats返回以下直方图:

histogram: [
  { micros: NumberLong(1), count: NumberLong(10) },
  { micros: NumberLong(2), count: NumberLong(1) },
  { micros: NumberLong(4096), count: NumberLong(1) },
  { micros: NumberLong(16384), count: NumberLong(1000) },
  { micros: NumberLong(49152), count: NumberLong(100) }
]

This indicates that there were:这表明:

  • 10 operations taking 1 microsecond or less,10次操作花费1微秒或更少,
  • 1 operation in the range (1, 2] microseconds,1次操作在范围(1, 2]微秒内
  • 1 operation in the range (3072, 4096] microseconds,1次操作在范围(3072, 4096]微秒内
  • 1000 operations in the range (12288, 16384], and1000次操作在范围(12288, 16384]微秒内
  • 100 operations in the range (32768, 49152].100次操作在范围(32768, 49152]微秒内

Examples示例

You can run latencyStats() in mongosh as follows:您可以在mongosh中运行latencyStats(),如下所示:

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

latencyStats() returns a document such as the following:返回如下文档:

{
  "ns" : "test.data",
  "localTime" : ISODate("2016-11-01T21:56:28.962Z"),
  "latencyStats" : {
    "reads" : {
      "histogram" : [
        {
          "micros" : NumberLong(16),
          "count" : NumberLong(6)
        },
        {
          "micros" : NumberLong(512),
          "count" : NumberLong(1)
        }
      ],
      "latency" : NumberLong(747),
      "ops" : NumberLong(7)
    },
    "writes" : {
      "histogram" : [
        {
          "micros" : NumberLong(64),
          "count" : NumberLong(1)
        },
        {
          "micros" : NumberLong(24576),
          "count" : NumberLong(1)
        }
      ],
      "latency" : NumberLong(26845),
      "ops" : NumberLong(2)
    },
    "commands" : {
      "histogram" : [ ],
      "latency" : NumberLong(0),
      "ops" : NumberLong(0)
    }
  }
}
←  db.collection.isCapped()db.collection.mapReduce() →