[SERVER-2212] Server automatically abort queries/commands after user-specified time limit Created: 13/Dec/10  Updated: 28/Feb/23  Resolved: 14/Nov/13

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: None
Fix Version/s: 2.5.4

Type: New Feature Priority: Major - P3
Reporter: ppalka Assignee: J Rassi
Resolution: Done Votes: 35
Labels: query_triage
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
depends on SERVER-10550 CurOp::_killPending not always cleare... Closed
is depended on by CSHARP-790 Server automatically abort queries/co... Closed
is depended on by DRIVERS-99 Add support for server automatically ... Closed
is depended on by JAVA-910 Support new $maxTimeMS field for all ... Closed
is depended on by PYTHON-550 Support $maxTimeMS for commands and q... Closed
is depended on by DOCS-1919 Document : Server automatically abort... Closed
Duplicate
is duplicated by SERVER-6761 db.coll.find(...).timeout(3000) shoul... Closed
is duplicated by SERVER-3379 Query Timeout Closed
Related
related to SERVER-3960 High CPU usage no IO Wait Closed
related to DOCS-9823 Document maxTimeMS option for all CRU... Closed
is related to SERVER-10382 Interrupted count commands don't retu... Closed
is related to SERVER-10995 Elapsed time for $maxTimeMS queries i... Closed
is related to SERVER-11216 Interrupted geoNear commands on mongo... Closed
is related to SERVER-11221 maxTimeMS(0.1) should return error Closed
is related to SERVER-11488 Supported mongos commands should prop... Closed
is related to SERVER-11243 Add server status counter "time limit... Closed
is related to SERVER-6113 Uneven distribution of yields are unfair Backlog
is related to SERVER-8499 Server Side setting for Max query exe... Backlog
is related to SERVER-11094 Javascript interruption should use se... Closed
is related to SERVER-11185 Time-interrupted operations should no... Closed
is related to SERVER-11361 RunOnAllShardsCommand::run() should s... Closed
is related to SERVER-4477 Interrupting compact can cause drop o... Closed
Participants:

 Description   

Add { $maxTimeMS: <integer> } as a query option, and add { maxTimeMS: <integer> } as a command option to all commands. Operations that exceed their time limit will be aborted, and an error will be returned to the client. A cursor.maxTimeMS() shell helper will be provided for queries.

Details:

  • An operation's "elapsed time" for the purpose of this feature will be the same as the operation's "elapsed time" as reported by the logging / profiling subsystems.
  • The abort semantics provided will be very similar to that of db.killOp():
    • Operations cannot currently be interrupted while waiting to acquire a lock (but this will be supported when SERVER-8579 is resolved).
    • Write operations are generally not interruptible once the first write occurs.
    • As a corollary, it is expected that operations which do not reach an interrupt point after exceeding the time limit will have an elapsed time longer than the time limit, and will be logged/profiled as such.
  • A query that completes in under its time limit will "roll over" its remaining time to the first getmore op (which will then "roll over" its remaining time to the second getmore op and so on, until the time limit is hit).
    • Cursors returned by successful time-limited queries will still obey the default cursor idle timeout (unless the "no cursor idle timeout" flag has been set).
  • For now, insert/update/delete will not support time-limited operations.


 Comments   
Comment by auto [ 01/Nov/13 ]

Author:

{u'username': u'jrassi', u'name': u'j. rassi', u'email': u'rassi@10gen.com'}

Message: SERVER-11501 SERVER-2212 Fix deref. of invalidated iterator
Branch: master
https://github.com/mongodb/mongo/commit/a6678a47b6e2700a502984cc1b990ded37f61c7f

Comment by auto [ 31/Oct/13 ]

Author:

{u'username': u'jrassi', u'name': u'Jason Rassi', u'email': u'rassi@10gen.com'}

Message: SERVER-11496 SERVER-2212 Fix race condition in max_time_ms_sharded.js

Wait for inserts to complete before expecting count to include them.
Branch: master
https://github.com/mongodb/mongo/commit/02d96b609930ce10ea82a4a317baf5731ed04989

Comment by auto [ 31/Oct/13 ]

Author:

{u'username': u'jrassi', u'name': u'Jason Rassi', u'email': u'rassi@10gen.com'}

Message: SERVER-2212 mongos maxTimeMS support for aggregate, count, mapReduce
Branch: master
https://github.com/mongodb/mongo/commit/59c349c00ecd5de1adb18f398a63917c36c8334b

Comment by auto [ 31/Oct/13 ]

Author:

{u'username': u'jrassi', u'name': u'Jason Rassi', u'email': u'rassi@10gen.com'}

Message: SERVER-2212 mongos maxTimeMS support for moveChunk
Branch: master
https://github.com/mongodb/mongo/commit/323abaca6f8168b4ff42d3fe08931e7fed3d0fc1

Comment by auto [ 31/Oct/13 ]

Author:

{u'username': u'jrassi', u'name': u'Jason Rassi', u'email': u'rassi@10gen.com'}

Message: SERVER-2212 mongos tracks elapsed time for sharded cursors

If a maxTimeMS sharded query exceeds its time limit, the next request
for a batch will fail with an error.
Branch: master
https://github.com/mongodb/mongo/commit/195c99e44a1483816b3be2a1f6f42bffed7ec18e

Comment by auto [ 31/Oct/13 ]

Author:

{u'username': u'jrassi', u'name': u'Jason Rassi', u'email': u'rassi@10gen.com'}

Message: SERVER-2212 Add addl. maxTimeMS parsing helpers to LiteParsedQuery
Branch: master
https://github.com/mongodb/mongo/commit/5c26124ba4a9829a417a8f652ce009eef0b98a72

Comment by auto [ 31/Oct/13 ]

Author:

{u'username': u'jrassi', u'name': u'Jason Rassi', u'email': u'rassi@10gen.com'}

Message: SERVER-2212 Pull lite_parsed_query.cpp out into static library
Branch: master
https://github.com/mongodb/mongo/commit/aaff692940fdf0a57f37d4e9b1d45d8203049647

Comment by auto [ 25/Sep/13 ]

Author:

{u'username': u'jrassi', u'name': u'Jason Rassi', u'email': u'rassi@10gen.com'}

Message: SERVER-2212 Add error code to AssertionException::interrupted() list
Branch: master
https://github.com/mongodb/mongo/commit/3b6112691e7c9e6ed42bc46f434c75d29c23a9b1

Comment by auto [ 25/Sep/13 ]

Author:

{u'username': u'jrassi', u'name': u'Jason Rassi', u'email': u'rassi@10gen.com'}

Message: SERVER-2212 Add new fail point maxTimeNeverTimeOut

Includes:

Comment by auto [ 16/Sep/13 ]

Author:

{u'username': u'jrassi', u'name': u'Jason Rassi', u'email': u'rassi@10gen.com'}

Message: SERVER-2212 max_time_ms.js use sleep command instead of eval command
Branch: master
https://github.com/mongodb/mongo/commit/a9506ab7fc36ed852415ef9931e56eecdf2ca867

Comment by auto [ 12/Sep/13 ]

Author:

{u'username': u'jrassi', u'name': u'Jason Rassi', u'email': u'rassi@10gen.com'}

Message: SERVER-2212 Separate processing of "$maxTimeMS" from "maxTimeMS"

Adds support for the command option "maxTimeMS", and removes
command support for "$maxTimeMS" query option.

For normal queries: specify "$maxTimeMS" as a top-level query option
(same as "$orderby").

For commands: specify "maxTimeMS" at the command document level
(inside $query if wrapping, otherwise top-level). The "$maxTimeMS"
query option cannot be used with commands.
Branch: master
https://github.com/mongodb/mongo/commit/63f777e29558b271c9cda72791553faf94cc3deb

Comment by auto [ 12/Sep/13 ]

Author:

{u'username': u'jrassi', u'name': u'Jason Rassi', u'email': u'rassi@10gen.com'}

Message: SERVER-2212 Minor block formatting in parsed_query.cpp
Branch: master
https://github.com/mongodb/mongo/commit/bf0055f56e4d0ff32a120f32e5597e1240c87c9d

Comment by auto [ 11/Sep/13 ]

Author:

{u'username': u'jrassi', u'name': u'Jason Rassi', u'email': u'rassi@10gen.com'}

Message: SERVER-2212 Move ExceededTimeLimit error code to semantic code range
Branch: master
https://github.com/mongodb/mongo/commit/5e15f8978b1456a2b8d120b741a22d43e07321b3

Comment by auto [ 26/Jul/13 ]

Author:

{u'username': u'jrassi', u'name': u'Jason Rassi', u'email': u'rassi@10gen.com'}

Message: SERVER-2212 Add mongod query option $maxTimeMS, shell helper

$maxTimeMS can be added as a top-level field to any query or
command ($cmd.sys.* ops not included). Requests op interruption
after the user-given time limit.
Branch: master
https://github.com/mongodb/mongo/commit/8a1429687d6259203db2d96b829e8e020b1a99e6

Comment by auto [ 26/Jul/13 ]

Author:

{u'username': u'jrassi', u'name': u'Jason Rassi', u'email': u'rassi@10gen.com'}

Message: SERVER-2212 Logic to apply time limits to getmore CurOp objects

If a CurOp object generating a cursor has a time limit imposed,
remaining time is "rolled over" to the ClientCursor object, and
applied to later getmore ops. Affects getmore ops on cursors
associated with both normal queries and cursor-enabled aggregation
commands.
Branch: master
https://github.com/mongodb/mongo/commit/07336d045cce6f11f0b3ceaeb327a8a8d438ae67

Comment by auto [ 26/Jul/13 ]

Author:

{u'username': u'jrassi', u'name': u'Jason Rassi', u'email': u'rassi@10gen.com'}

Message: SERVER-2212 Ability for CurOp objects to be "timer-interruptible"

Comment by auto [ 26/Jul/13 ]

Author:

{u'username': u'jrassi', u'name': u'Jason Rassi', u'email': u'rassi@10gen.com'}

Message: SERVER-2212 Add CurOp public method elapsedMicros()
Branch: master
https://github.com/mongodb/mongo/commit/6f8b9d5515591beaaa6f58c8fdabb9ddd2b2450f

Comment by auto [ 26/Jul/13 ]

Author:

{u'username': u'jrassi', u'name': u'Jason Rassi', u'email': u'rassi@10gen.com'}

Message: SERVER-2212 Misc. comments, formatting
Branch: master
https://github.com/mongodb/mongo/commit/e721e9df43caf1433040dde1fd7ff54384f2497d

Comment by Chelliah Thirunavukkarasu [ 17/Apr/13 ]

In the interim, would it be possible to change db.currentOp() to at least print query's comment? We have written a "governor" that kills queries if they have exceeded a time limit and we are using db.currentOp() to get the list of queries. We also use query's comment to mark the queries that are safe to be killed. If the query expression is too complicated, db.currentOp() does not print the query and therefore the query comment and this prevents us from reliably identifying the queries that are safe to be killed.

Comment by Victor [ 14/Jun/11 ]

It would be great that not only JDBC driver stopped waiting for long query but also server killed the query.
For example, in MySQL's JDBC driver you can set "queryTime" parameter on Statement/query - this way JDBC driver will send "KILL QUERY <query_id>" command to MySQL server.

Comment by Alexey Palazhchenko [ 19/May/11 ]

Something like $maxTime would be very helpful. I noticed a situation when HTTP requests were timed out, but queries are running in database.

Comment by Adrien Mogenet [ 12/Jan/11 ]

$maxScan or $maxTime ? (maybe $maxScan could be a hint for query optimizer when browsing indexes ?)

Generated at Thu Feb 08 02:59:18 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.