Forcing connection to a local mongos + verbose logging that specifies

52 views
Skip to first unread message

Guillaume Forget

unread,
Oct 19, 2013, 7:59:58 PM10/19/13
to mongod...@googlegroups.com
Hello,

We are using MongoDB for a Java web app running on Amazon EC2 machines across 3 availability zones (AZ). On each machine, we have one Java VM and one mongos. When initializing the connection to Mongo, we specify localhost and 3 other machines (possibly the local one) that are located in different AZs for failover scenarios. Once in a while I will see a read timeout specifying a mongos that isn't the one running locally. Ideally I'd like to force the connection to the local mongos unless it's dead. Is it possible? The javadoc for the Java driver indicates that the driver will pick the host with the lowest ping time. I have a hard time to believe that this will not be the localhost one.

Also, is it possible to turn on some logging which will print out the query being sent and which server it was sent to? I looked at the source code of the Java driver but didn't see anything.

Thanks

Gui

Jeff Yemin

unread,
Oct 20, 2013, 9:33:32 AM10/20/13
to mongod...@googlegroups.com
Yes, it's a bit strange, but the selection of a mongos with lowest ping time is "sticky", so if it happens that randomly the local mongos doesn't have the fastest ping time right at startup, the driver will stick to one of the non-local ones.

The driver doesn't log every query currently, so your best bet is to use the server logs to monitor.

There are a couple of related Jira issues that you can watch:



Regards,
Jeff




--
--
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
See also the IRC channel -- freenode.net#mongodb
 
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Guillaume Forget

unread,
Oct 24, 2013, 10:54:54 PM10/24/13
to mongod...@googlegroups.com
Hey Jeff,

Thanks for the response. I wasn't so much "complaining" about the stickiness but rather the fact that if I specify multiple mongos addresses, I don't get to specify a preferred one which in my case would be localhost.

And on the same topic, I'm very confused with the following behavior:  I'm initializing the Mongo instance (Java object) with the following options:
2013-10-24 21:30:35,906 [http-8080-exec-6] INFO  Mongo{authority=MongoAuthority{type=Set, serverAddresses=[localhost/127.0.0.1:27027, HOST1/10.149.12.79:27027, HOST2/10.154.149.70:27027, HOST3/10.158.33.16:27027], credentials={credentials={}}}, options=MongoOptions{description='null', connectionsPerHost=40, threadsAllowedToBlockForConnectionMultiplier=5, maxWaitTime=10000, connectTimeout=10000, socketTimeout=30000, socketKeepAlive=false, autoConnectRetry=false, maxAutoConnectRetryTime=0, slaveOk=false, readPreference=secondaryPreferred : { "tags" : [ { "aws-az" : "us-east-1e"}]}, dbDecoderFactory=DefaultDBDecoder.DefaultFactory, dbEncoderFactory=DefaultDBEncoder.DefaultFactory, safe=false, w=0, wtimeout=0, fsync=false, j=false, socketFactory=javax.net.DefaultSocketFactory@20c66135, cursorFinalizerEnabled=true, writeConcern=WriteConcern { "getlasterror" : 1} / (Continue Inserting on Errors? false), alwaysUseMBeans=false}}

HOST1, HOST2 and HOST3 are dead when I start due to a bad config. And I get the following error:
com.mongodb.MongoException: can't find a master
        at com.mongodb.DBTCPConnector.checkMaster(DBTCPConnector.java:517)
        at com.mongodb.DBTCPConnector.say(DBTCPConnector.java:134)
        at com.mongodb.DBTCPConnector.say(DBTCPConnector.java:115)
        at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:248)


If I start with the following options:
2013-10-24 21:43:13,608 [http-8080-exec-19] INFO  Mongo{authority=MongoAuthority{type=Set, serverAddresses=[localhost/127.0.0.1:27027], credentials={credentials={}}}, options=MongoOptions{description='null', connectionsPerHost=40, threadsAllowedToBlockForConnectionMultiplier=5, maxWaitTime=10000, connectTimeout=10000, socketTimeout=30000, socketKeepAlive=false, autoConnectRetry=false, maxAutoConnectRetryTime=0, slaveOk=false, readPreference=secondaryPreferred : { "tags" : [ { "aws-az" : "us-east-1e"}]}, dbDecoderFactory=DefaultDBDecoder.DefaultFactory, dbEncoderFactory=DefaultDBEncoder.DefaultFactory, safe=false, w=0, wtimeout=0, fsync=false, j=false, socketFactory=javax.net.DefaultSocketFactory@2cc29d3d, cursorFinalizerEnabled=true, writeConcern=WriteConcern { "getlasterror" : 1} / (Continue Inserting on Errors? false), alwaysUseMBeans=false}}

Then it starts fine. It's as if it ignored the localhost entry in the first case. I can reproduce this at will. Is this a bug or am I missing something?

Gui

Jeff Yemin

unread,
Oct 28, 2013, 5:40:56 PM10/28/13
to mongod...@googlegroups.com
Hi Gui,

This is not the behavior that I expect.  Would you mind opening a JIRA issue?


Regards,
Jeff

Reply all
Reply to author
Forward
0 new messages