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

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

重要

mongosh 方法

本页介绍了 mongosh 方法。这不是数据库命令或特定语言驱动程序(例如 Node.js)的文档。

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

对于MongoDB API驱动程序,请参阅特定语言的MongoDB驾驶员文档。

db.collection.latencyStats(options)

db.collection.latencyStats() 返回给定集合的延迟统计信息。它是 $collStats 的包装器。

此方法的形式为:

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

histograms 参数是一个可选的布尔值。如果 histograms: true then latencyStats() 将延迟直方图添加到返回文档中。

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

  • MongoDB Atlas :用于在云中部署MongoDB 的完全托管服务

注意

所有MongoDB Atlas集群都支持此命令。有关Atlas支持所有命令的信息,请参阅不支持的命令。

latencyStats() 返回包含字段latencyStats 的文档,其中包含以下字段:

字段名称
说明

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

这表明存在 [1]:

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

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

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

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

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

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

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

您可以在 mongosh 中运行latencyStats(),如下所示:

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