VaidAbhishek
VaidAbhishek

Reputation: 6144

Mongo maxTimeMS doens't kill query immediately

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

Upvotes: 5

Views: 5837

Answers (1)

John Petrone
John Petrone

Reputation: 27497

Yes, this can be expected behavior. The two times being measured are somewhat different, secs_running is total elapsed time to run while maxTimeMS is actual running time:

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.

and

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

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

You can have other processes running at the same time, so in an extreme case with many heavy queries/updates going secs_running could be much larger than the desired maxTimeMS. In your case numYields of 4111 indicates it yielded processing 4111 times, during which elapsed time increased but processing time did not.

Upvotes: 9

Related Questions