Database Manual / Reference / mongosh Methods / Collections

db.collection.latencyStats() (mongosh method方法)

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.本页记录了一种mongosh方法。这不是数据库命令或特定语言驱动程序(如Node.js)的文档。

For the database command, see the latencyStats field returned by the collStats command.对于数据库命令,请参阅collStats命令返回的latencyStats字段。

For MongoDB API drivers, refer to the language-specific MongoDB driver documentation.有关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. If histograms: true then latencyStats() adds latency histograms to the return document.histograms(直方图)参数是一个可选的布尔值。如果histograms: true,则latencyStats()将延迟直方图添加到返回文档中。

Compatibility兼容性

This method is available in deployments hosted in the following environments:此方法在以下环境中托管的部署中可用:

  • MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud:云中MongoDB部署的完全托管服务

Note

This command is supported in all MongoDB Atlas clusters. For information on Atlas support for all commands, see Unsupported Commands.所有MongoDB Atlas集群都支持此命令。有关Atlas支持所有命令的信息,请参阅不支持的命令

  • MongoDB Enterprise: The subscription-based, self-managed version of MongoDB:MongoDB的基于订阅的自我管理版本
  • MongoDB Community: The source-available, free-to-use, and self-managed version of MongoDB:MongoDB的源代码可用、免费使用和自我管理版本

Output输出

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

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 with the following fields:每个字段都包含一个嵌入式文档,其中包含以下字段:

Field Name字段名称Description描述
latencyThe total latency, in microseconds.总延迟,单位为微秒。
opsThe total number of operations performed on the collection since startup.自启动以来对集合执行的操作总数。
histogram

An array of embedded documents, each representing a latency range. Each document covers twice the previous document's range. For lower 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. Empty ranges with a zero count are omitted from the output.此字段仅在给定latencyStats: { histograms: true }选项时存在。输出中省略了count为零的空范围。

Each document has the following fields:每个文档都有以下字段:

Field Name字段名称Description描述
micros

The inclusive lower bound of the current latency range, in microseconds.当前延迟范围的下限,单位为微秒。

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

countThe number of operations with latency less than or equal to micros.延迟小于或等于micros的操作数。

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

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

This indicates that there were [1]:这表明存在[1]

  • 10 operations taking 2 microsecond or less10次操作耗时2微秒或更短
  • 1 operation in the range [2, 4) microseconds在[2, 4)微秒范围内执行1次操作
  • 1 operation in the range [4096, 6144) microseconds在[4096, 6144)微秒范围内执行1次操作
  • 1000 operations in the range [16384, 24576) microseconds在[16384, 24576)微秒范围内执行1000次操作
  • 100 operations in the range [49152, 65536) microseconds在[49152, 65536)微秒范围内执行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" : Long(16),
"count" : Long(6)
},
{
"micros" : Long(512),
"count" : Long(1)
}
],
"latency" : Long(747),
"ops" : Long(7)
},
"writes" : {
"histogram" : [
{
"micros" : Long(64),
"count" : Long(1)
},
{
"micros" : Long(24576),
"count" : Long(1)
}
],
"latency" : Long(26845),
"ops" : Long(2)
},
"commands" : {
"histogram" : [ ],
"latency" : Long(0),
"ops" : Long(0)
}
}
}