Mongo maxTimeMS做得很好。

时间:2014-07-25 21:23:27

标签: mongodb

  • 在我的理解中,当查询已经超过它的分配时间时,maxTimeMS应该立即终止查询(+ - 2,3秒)。但是,mongo并没有立即查询并花费太多时间。

  • 可以看到在currentOp()的输出后观察到

{     " inprog" :[         {             " OPID" :176078308,             "有源" :真的,             " secs_running" :105,             " OP" :"查询",             " NS" :" xxx",             "查询" :{                 "聚合" :"推文",                 "管道" :[                     {                         " $匹配" :{                             " GTS" :{                                 " $ LTE" :ISODate(" 2014-07-25T22:00:00Z"),                                 " $ GTE" :ISODate(" 2014-07-20T21:00:00Z")                             },                             " RE_H" :{                                 " $在" :[                                     NumberLong(" 884327843395156951&#34)                                 ]                             }                         }                     },                     {                         " $匹配" :{                             " $和" :[                                 {                                     " L" :{                                         " $在" :[                                             "班德拉&#34 ;,                                             "孟买&#34 ;,                                             "塔纳&#34 ;,                                             "孟买&#34 ;,                                             "马希姆"                                         ]                                     }                                 },                                 {                                     " TS" :{                                         " $ LTE" :ISODate(" 2014-07-25T21:16:00Z"),                                         " $ GTE" :ISODate(" 2014-07-20T21:16:00Z")                                     }                                 }                             ]                         }                     },                     {                         " $项目" :{                             "!" :1,                             " S" :1,                             " NR" :1,                             " TS" :1                         }                     }                 ]                 "光标" :{

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

}

  • 此查询的maxTimeMS为 60秒(60,000 ms),并且持续 105秒。在我看来,这太荒谬了。 Mongo在60秒内不应超过2,3秒才能杀死它。

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

1 个答案:

答案 0 :(得分:6)

是的,这可能是预期的行为。测量的两次有些不同,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次,在此期间经过的时间增加但处理时间没有。