【问题标题】:Mongo maxTimeMS doens't kill query immediatelyMongo maxTimeMS 不会立即终止查询
【发布时间】:2014-09-17 20:06:59
【问题描述】:
  • 据我了解,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 的预期行为吗?

【问题讨论】:

    标签: mongodb


    【解决方案1】:

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

    currentOp.secs_running

    操作的持续时间(以秒为单位)。 MongoDB 计算这个 值通过从开始时间减去当前时间 操作。

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

    cursor.maxTimeMS() 定义

    2.6 版中的新功能。

    cursor.maxTimeMS()

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

    游标的空闲时间不影响其处理时间。

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

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

    【讨论】:

    • 谢谢你说得通。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-19
    • 1970-01-01
    • 2012-01-18
    • 2014-08-02
    • 1970-01-01
    • 2023-01-04
    • 1970-01-01
    相关资源
    最近更新 更多