gpt4 book ai didi

mongodb - Mongo maxTimeMS 不会立即终止查询

转载 作者:可可西里 更新时间:2023-11-01 09:58:02 25 4
gpt4 key购买 nike

  • 根据我的理解,maxTimeMS 应该在查询超过分配的时间后立即终止查询(+- 2.3 秒)。然而,mongo 并没有立即终止查询并且花费了太多时间。

  • 可以看到 currentOp() 的以下输出来观察这一点

{
"inprog" : [
{
"opid" : 176078308,
"active" : true,
"secs_running" : 105,
"op" : "query",
"ns" : "xxx",
"query" : {
"aggregate" : "tweets",
"pipeline" : [
{
"$match" : {
"gTs" : {
"$lte" : ISODate("2014-07-25T22:00:00Z"),
"$gte" : ISODate("2014-07-20T21:00:00Z")
},
"RE_H" : {
"$in" : [
NumberLong("884327843395156951")
]
}
}
},
{
"$match" : {
"$and" : [
{
"l" : {
"$in" : [
"bandra",
"mumbai",
"thane",
"bombay",
"mahim"
]
}
},
{
"ts" : {
"$lte" : ISODate("2014-07-25T21:16:00Z"),
"$gte" : ISODate("2014-07-20T21:16:00Z")
}
}
]
}
},
{
"$project" : {
"!" : 1,
"s" : 1,
"nR" : 1,
"ts" : 1
}
}
],
"cursor" : {

},
"maxTimeMS" : 60000
},
"client" : "xxx.xxx.xxx.xxx",
"desc" : "conn56556",
"threadId" : "0x7f96e1cf6700",
"connectionId" : 56556,
"waitingForLock" : false,
"numYields" : 4111,
"lockStats" : {
"timeLockedMicros" : {
"r" : NumberLong(16472467),
"w" : NumberLong(0)
},
"timeAcquiringMicros" : {
"r" : NumberLong(106194),
"w" : NumberLong(0)
}
}
}
]
}
  • 此查询的 maxTimeMS60 秒(60,000 毫秒),并持续 105 秒。在我看来,这是荒谬的。 Mongo 在 60 秒内不应超过 2、3 秒才能杀死它。

  • 有人可以确认这是否是 Mongo 的预期行为吗?

最佳答案

是的,这是可以预期的行为。两次测量的时间有些不同,secs_running 是运行的总运行时间,而 maxTimeMS 是实际运行时间:

currentOp.secs_running

The duration of the operation in seconds. MongoDB calculates this value by subtracting the current time from the start time of the operation.

http://docs.mongodb.org/manual/reference/method/db.currentOp/

cursor.maxTimeMS() Definition

New in version 2.6.

cursor.maxTimeMS()

Specifies a cumulative time limit in milliseconds for processing operations on a cursor.

A cursor’s idle time does not contribute towards its processing time.

http://docs.mongodb.org/manual/reference/method/cursor.maxTimeMS/#cursor.maxTimeMS

您可以同时运行其他进程,因此在极端情况下,许多繁重的查询/更新正在进行 secs_running 可能比所需的 maxTimeMS 大得多。在您的情况下,numYields 为 4111 表示它产生了 4111 次处理,在此期间耗时增加但处理时间没有增加。

关于mongodb - Mongo maxTimeMS 不会立即终止查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24964708/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com