How to increase a query timeout?

4,716 views
Skip to first unread message

Mr. Flibble

unread,
Apr 13, 2011, 5:17:20 AM4/13/11
to mongod...@googlegroups.com
I have been experiencing timeouts while querying a higly loaded database. I have tried to increase the timeout settings to allow more time for the query to complete, but I still get timeouts. I am using the following connection string (C# Driver) to try ans increase the timeout settings:
mongodb://localhost/?connecttimeout=600&maxconnectionlifetime=600

Are there other properties that I should set to allow a query more time to complete?

The timeout exception looks like this:
Exception: System.IO.IOException: Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a pe
riod of time, or established connection failed because connected host has failed to respond. ---> System.Net.Sockets.SocketException: A connection attem0pt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   --- End of inner exception stack trace ---
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   at MongoDB.Bson.IO.BsonBuffer.LoadFrom(Stream stream, Int32 count)
   at MongoDB.Bson.IO.BsonBuffer.LoadFrom(Stream stream)
   at MongoDB.Driver.Internal.MongoConnection.ReceiveMessage[TDocument](MongoServer server)
   at MongoDB.Driver.Internal.MongoCursorEnumerator`1.GetReply(MongoRequestMessage message)
   at MongoDB.Driver.Internal.MongoCursorEnumerator`1.GetMore()
   at MongoDB.Driver.Internal.MongoCursorEnumerator`1.MoveNext()
   

Nat

unread,
Apr 13, 2011, 5:28:01 AM4/13/11
to mongodb-user
You should increase sockettimeout instead. The default is 30 seconds.

Mr. Flibble

unread,
Apr 13, 2011, 6:25:28 AM4/13/11
to mongod...@googlegroups.com
Thank you Nat. I tried that (new connection string: mongodb://localhost/?connecttimeout=60000&maxconnectionlifetime=60000&sockettimeout=60000)
but got the same error after around 12 minutes.

Nat

unread,
Apr 13, 2011, 6:38:32 AM4/13/11
to mongod...@googlegroups.com
Sockettimeout should be specified in timespan format. If you want to specify in milliseconds, you can use sockettimeoutms instead.
From: "Mr. Flibble" <conor.m...@gmail.com>
Date: Wed, 13 Apr 2011 03:25:28 -0700 (PDT)
Subject: [mongodb-user] Re: How to increase a query timeout?

Thank you Nat. I tried that (new connection string: mongodb://localhost/?connecttimeout=60000&maxconnectionlifetime=60000&sockettimeout=60000)
but got the same error after around 12 minutes.

--
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com.
To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.

Nat

unread,
Apr 13, 2011, 6:43:52 AM4/13/11
to mongodb-user
- Also make sure that you use the latest c# driver as it's a new
feature in recent versions.
- For connection reference, please take a look at
http://www.mongodb.org/display/DOCS/Connections
- As the default is 30 seconds, if it's timeout. It could be that you
do something wrong. It's worth checking mongostat, db.currentOp() to
find out what's blocking.

Mr. Flibble

unread,
Apr 13, 2011, 7:21:03 AM4/13/11
to mongod...@googlegroups.com
Thanks Nat. Using sockettimeoutms has fixed my problem. 

I'm returning a million documents while also bombarding the database with inserts, so I expect the query to take a long time. 
Reply all
Reply to author
Forward
0 new messages