对于 AI 代理:可在 https://www.mongodb.com/zh-cn/docs/llms.txt 获取文档索引—通过在任何 URL 路径后添加 .md 可获取所有页面的 Markdown 版本。
Docs 菜单

db. 集合.latencyStats()(mongosh方法)

重要

mongosh 方法

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

有关数据库命令,请参阅 collStats 命令返回的 latencyStats 字段。

如需了解 MongoDB API 驱动程序,请参阅特定语言的 MongoDB 驱动程序文档。

db.collection.latencyStats(options)

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

此方法的形式为:

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

The histograms argument is an optional boolean. If histograms: true then latencyStats() adds latency histograms to the return document.

此方法可用于以下环境中托管的部署:

  • MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud

注意

This command is supported in all MongoDB Atlas clusters. For information on Atlas support for all commands, see Unsupported Commands.

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

字段名称
说明

reads

读取请求的延迟统计信息。

writes

写入请求的延迟统计数据。

commands

数据库命令的延迟统计信息。

transactions

数据库事务的延迟统计信息。

其中每个字段都包含一个包含以下字段的嵌入式文档:

字段名称
说明

latency

总延迟(以微秒为单位)。

ops

自初创企业以来对集合执行的操作总数。

histogram

嵌入式文档大量,每个文档代表一个延迟范围。 每个文档的覆盖范围是前一个文档范围的两倍。 对于介于2048微秒到大约1秒之间的较低值,直方图包括半步。

此字段仅在给定 latencyStats: { histograms: true } 选项时存在。输出中将省略带有零 count 的空范围。

每个文档都包含以下字段:

  • micros:当前延迟范围的包含下限,以微秒为单位。

    文档的范围介于上一文档的 micros 值(不含)和本文档的 micros 值(含)之间。

  • count:延迟小于或等于 micros 的操作次数。

例如,如果 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]:

  • 10操作用时2微秒或更短

  • 1操作,范围[ 2 , 4 ) 微秒

  • 1操作,范围[ 4096 , 6144 ) 微秒

  • 在 [ 16384 , 24576 ) 微秒范围执行1000次操作

  • 在 [ 49152 , 65536 ) 微秒范围执行100次操作

[1]
  • 此页上的 ( 符号表示表示该值不包含在内。

  • 本页中的 ] 符号表示该值包含在内。

You can run latencyStats() in mongosh as follows:

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

latencyStats() 返回如下文档:

{
"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)
}
}
}
给本页内容打分