Docs HomeMongoDB Manual

db.collection.latencyStats()

On this page本页内容

Definition定义

db.collection.latencyStats(options)
Important

mongosh Method

This page documents a mongosh method. This is not the documentation for database commands or language-specific drivers, such as Node.js.

For the database command, see the latencyStats field returned by the collStats command.

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

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

mongo shell v4.4

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: 另请参阅:

$collStats

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.数据库命令的延迟统计信息。
transactionsLatency statistics for database transactions.数据库事务的延迟统计信息。

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位整数,给出自启动以来对集合执行的操作总数。
histogramAn 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描述
microsA 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值(排除)和此文档的micro值(包含)之间。
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 [1]:这表明存在[1]

  • 10 operations taking 1 microsecond or less耗时1微秒或更短的10次操作
  • 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] microseconds(12288, 16384]微秒的范围内的1000次操作
  • 100 operations in the range (32768, 49152] microseconds(32768, 49152]微秒范围内的100次操作
[1]
  • The ( symbol notation on this page means the value is exclusive.此页上的(符号表示该值是排除的。
  • The ] symbol notation on this page means the value is inclusive.此页上的]符号表示该值包含在内。

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)
}
}
}