Can't configure Java Client Driver timeout

313 views
Skip to first unread message

Diogo Vernier

unread,
Oct 14, 2011, 11:01:53 AM10/14/11
to mongodb-user
Hi,

To make a test, we've commented in /etc/hosts all the entries of the
replica sets, and started the application. But only after 60 seconds
an exception is thrown.

Setting connectTimeout, socketTimeout or waitTimeout to a proper
value, didn't change this behavior.

In this test, we were using the Java client driver 2.6.5, and the
following constructor http://api.mongodb.org/java/2.6/com/mongodb/Mongo.html#Mongo(java.util.List,
com.mongodb.MongoOptions)

Do you know some way to decrease this 60 seconds timeout?

Tks,

Diogo

Eliot Horowitz

unread,
Oct 14, 2011, 9:17:33 PM10/14/11
to mongod...@googlegroups.com
What are you testing exactly?
What error are you getting after 60 seconds?

> --
> 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.
>
>

Diogo Vernier

unread,
Oct 17, 2011, 5:52:24 PM10/17/11
to mongodb-user
Hi Eliot,

The test is this:

1) We make a request to a probe URL, in which the application calls a
findOne(null) in some collection...

dvsantos@host-68880:~$ time curl -v "http://127.0.0.1:9030/probe"
* About to connect() to 127.0.0.1 port 9030 (#0)
* Trying 127.0.0.1... connected
* Connected to 127.0.0.1 (127.0.0.1) port 9030 (#0)
> GET /probe HTTP/1.1
> User-Agent: curl/7.21.3 (i686-pc-linux-gnu) libcurl/7.21.3 OpenSSL/0.9.8o zlib/1.2.3.4 libidn/1.18
> Host: 127.0.0.1:9030
> Accept: */*
>

< HTTP/1.1 500 Server Error
< Content-Length: 0
< Server: Jetty(7.5.0.RC2)
<
* Connection #0 to host 127.0.0.1 left intact
* Closing connection #0

real 1m55.409s
user 0m0.000s
sys 0m0.004s


2) ... and after a certain time, we get an error like this:

Oct 17, 2011 6:36:34 PM com.mongodb.ReplicaSetStatus$Node update
WARNING: Server seen down: mongo1:27017
Oct 17, 2011 6:37:14 PM com.mongodb.ReplicaSetStatus$Node update
WARNING: Server seen down: mongo2:27017
Oct 17, 2011 6:38:14 PM com.mongodb.ReplicaSetStatus$Node update
WARNING: Server seen down: mongo3:27017
[ERROR] [17-10-2011 18:38:14.773] [u.n.r.service.FeedsReaderService]
3091 - Unable to probe external dependency, MongoBD is unavailable
(error-seq: host-68880-1)
uol.newsfeed.commons.exception.DBCollectionWrapperException: An error
occurred while executing the query null in the collection feed
at
uol.newsfeed.commons.mongo.DBCollectionWrapper.findOne(DBCollectionWrapper.java:
43)
at
uol.newsfeed.reader.service.impl.DefaultProbeService.probe(DefaultProbeService.java:
53)
Caused by: com.mongodb.MongoException: can't find a master
at com.mongodb.DBTCPConnector.checkMaster(DBTCPConnector.java:406)
at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:193)


It happens when the lines of the replica sets (mongo1, mongo2, mongo3)
are commented in /etc/hosts.

P.S: It is not always 60 seconds as I said, but I can't find a way to
decrease or control this timeout.



On Oct 14, 11:17 pm, Eliot Horowitz <el...@10gen.com> wrote:
> What are you testing exactly?
> What error are you getting after 60 seconds?
>
>
>
>
>
>
>
> On Fri, Oct 14, 2011 at 11:01 AM, Diogo Vernier <verni...@gmail.com> wrote:
> > Hi,
>
> > To make a test, we've commented in /etc/hosts all the entries of the
> > replica sets, and started the application. But only after 60 seconds
> > an exception is thrown.
>
> > Setting connectTimeout, socketTimeout or waitTimeout to a proper
> > value, didn't change this behavior.
>
> > In this test, we were using theJavaclientdriver2.6.5, and the
> > following constructorhttp://api.mongodb.org/java/2.6/com/mongodb/Mongo.html#Mongo(java.uti...,

Eliot Horowitz

unread,
Oct 17, 2011, 11:07:41 PM10/17/11
to mongod...@googlegroups.com
What are you setting in MongoOptions?

Antoine Girbal

unread,
Oct 18, 2011, 1:56:51 AM10/18/11
to mongodb-user
The default timeout on the driver's maintenance thread is 20s for
connection.
It sounds like by removing the entries from /etc/hosts, the connection
attempt to those hosts just hang.
This may be because the DNS just takes a while to come back, or it
gives a bogus IP that is not reachable.
Since there are 3 servers, and maintenance thread tries to update all
3 sequentially to find a master, it takes 60s before it throws an
error.
This should not be a big issue though:
- In most failure scenarios, the server will give an error right away,
for example a connection RST.
- if only 1 server is totally unreachable, the maintenance thread may
block on it 20s.
If you think this is a problem for your application, you may want to
open a ticket for the java driver.
Maybe the driver should take the min(20s, MongoOptions.timeout)

Diogo Vernier

unread,
Oct 18, 2011, 11:41:00 AM10/18/11
to mongodb-user
Eliot, I've only customized the following settings:

autoConnectRetry=false
connectionsPerHost=35
connectTimeout=1000
maxWaitTime=1000
socketTimeout=1000
threadsAllowedToBlock=100

Antoine,

I verified here, and what happened in this test is that the DNS gave
us an unreachable bogus IP. I'll try now testing other failure
cenarios.

The only problem I see is if some network unavailability happens when
the system is under high load, and the application threads start to
hang for more than 20 seconds.

However, It shouldn't be a major problem if, as you said, it would
work in most failure cenarios. Anyway, a maintenanceTimeout behavior
like min(20s, MongoOptions.timeout) would be better.

Tks,

Diogo

Antoine Girbal

unread,
Oct 18, 2011, 12:37:59 PM10/18/11
to mongodb-user
I created a ticket for this
https://jira.mongodb.org/browse/JAVA-452
Reply all
Reply to author
Forward
0 new messages