Skip to content

maxTime in DocumentDB not working

0

Hi, I am trying to automatically timeout the long running queries on documentDB using maxTime as suggested in this post.

It is working fine in terminating the query but does not terminate after the exact time that I mention with maxTime(5, TimeUnit.SECONDS). I first tried by API Gateway by hitting the API that queries DocumentDB, the request got terminated after 12000ms but that I could understand of lambda or network overheads.

Then, I tried to direct query documentDB using datagrip but there as well the same issue was there. I ran the query like db.collection.find(//some query).maxTimeMS(5000) and then simultaneously dp.currentOp() and I was able to see that the operation was running for 10 seconds and eventually got terminated after 11 seconds.

I want to understand why does this happen, does anyone have some reasoning for it?

asked 2 years ago432 views

2 Answers
0
Accepted Answer

Follow as mentioned above in the comment.

Note:

Query Execution Time (Time taken by the database server to actually process and execute the query) vs. Total Operation Time (Overall time from when a client initiates a query request to when it receives the complete results.): The maxTime parameter sets a time limit for the actual execution time of the query on the server. However, there are other operations involved in the complete process, such as Network latency, Query planning and optimization or Result serialization and transmission

Granularity of Checks: DocumentDB doesn't check the elapsed time continuously. Instead, it performs periodic checks during query execution. This means that the actual termination might occur slightly after the specified time.

Server-side vs. Client-side Timing: The maxTime is enforced on the server-side. The time you observe on the client-side includes additional overheads.

System Load and Resources: The exact timing of the termination can be influenced by the current system load, available resources, and other concurrent operations.

Clock Synchronization: There might be slight differences in clock synchronization between the client and the server.

Implementation Details: The exact implementation of the maxTime feature in DocumentDB might introduce some additional overhead or delay.

The additional 6 seconds over the specified 5 seconds could be due to a combination of the factors mentioned above, primarily the granularity of time checks and the total operation time vs. query execution time.

maxTime is a useful feature for preventing runaway queries, Its primary purpose is to prevent queries from running for excessively long periods, not to enforce exact execution times.

AWS

answered 2 years ago

0

The maxTimeMS function in DocumentDB sets a time limit for an operation but doesn't guarantee termination exactly at that limit. The check for timeout happens only at certain points during execution, not continuously.

Network latency or other overheads can also cause delays. AWS DocumentDB queries have a default timeout of 2 hours and as of a certain date, they didn't support the maxTimeMS setting.

If delays persist, consider scaling up your DocumentDB instance.

EXPERT

answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.