db.collection.latencyStats()

On this page本页内容

Definition定义

db.collection.latencyStats(options)

mongo Shell Method

This page documents the mongo shell method, and does not refer to the MongoDB Node.js driver (or any other driver) method. 本页记录了mongo shell方法,未提及MongoDB Node.js驱动程序(或任何其他驱动程序)方法。For corresponding MongoDB driver API, refer to your specific MongoDB driver documentation instead.有关相应的MongoDB驱动程序API,请参阅特定的MongoDB驱动程序文档。

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()会将延迟直方图添加到返回文档中。

See also参阅

$collStats

Output输出

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

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

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

Field Name字段名Description描述
latency A 64-bit integer giving the total combined latency in microseconds.一个64位整数,给出以微秒为单位的总组合延迟。
ops A 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.从输出中忽略count为零的空范围。

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.文档的范围介于上一个文档的micros值(独占)和此文档的micros值(包含)之间。

count A 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,2]微秒范围内进行1次操作,
  • 1 operation in the range (3072, 4096] microseconds,在(3072, 4096]微秒范围内进行1次操作,
  • 1000 operations in the range (12288, 16384], and在(12288, 16384]范围内进行1000次操作,以及
  • 100 operations in the range (32768, 49152].在(32768, 49152]范围内进行100次操作。

Examples示例

You can run latencyStats() in a mongo shell as follows:您可以在mongo shell中运行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)
    }
  }
}