Does anybody know how to add in a timeout for queries on the server side of MongoDb? Not a client side timeout (I am using the C# driver). I have a problem where the client crashes, and the connection to Mongo dies, but the server continues to execute queries. This causes a huge buildup of needless/outdated queries in the server's queue.
-
can you add an example of the queries you are running - are you setting any write safety options? Something that's a little unclear - if the connection goes away, then where are the new queries coming from, or is it only for a certain amount of time that the queries continue?Adam Comerford– Adam Comerford2012-02-16 10:49:18 +00:00Commented Feb 16, 2012 at 10:49
-
1@AdamC: there might be a veeeery long running query, and, even if connection dies, it keeps running, blocking other queries, despite the fact that no one want its result. I had a couple of these.Sergio Tulentsev– Sergio Tulentsev2012-02-16 11:16:54 +00:00Commented Feb 16, 2012 at 11:16
-
@Sergio got it right. I have multiple clients contacting the server at any given time. X sends a complicated query to the db and subsequently crashes... the server keeps executing that query even though its connection to X has ended.carlbenson– carlbenson2012-02-16 14:40:42 +00:00Commented Feb 16, 2012 at 14:40
-
hmm, quite a few queries have no action in terms of a return in MongoDB - an insert/update for example - the fact that the client goes away has no impact on the query's behavior....I think I have a potential answer though - will post belowAdam Comerford– Adam Comerford2012-02-16 15:10:26 +00:00Commented Feb 16, 2012 at 15:10
1 Answer
If you have these long running queries from a prior client connection that you want to stop/kill, then you would need to either manually kill them per:
http://www.mongodb.org/display/DOCS/Viewing+and+Terminating+Current+Operation
Or, at the startup of your new client you could do something more programmatic (get last run queries from a log, kill them because they are from the previous client). Whether you can programmatically identify the operations you want to kill and avoid killing others is the key here - may require you to add some logging in your app to track in-flight operation.
1 Comment
db.currentOp() for operations where secs_running is greater that, let say, 600 I'd like mongo DB engine to kill such queries...