mongo-db java driver 2.10.x connection timeout problem

2,513 views
Skip to first unread message

Amarnath Bhattacharya

unread,
Jul 15, 2014, 12:07:19 AM7/15/14
to mongod...@googlegroups.com

I've developed a CMS(Content Management System) with MONGO DB using JAVA,SpringData-MongoDB for one of our client.But in one environment at client premises called Performance Environment I'm getting the error:

Caused by: java.net.SocketTimeoutException: Read timed out 
       at java.net.SocketInputStream.socketRead0(Native Method) 
       at java.net.SocketInputStream.read(SocketInputStream.java:150) 
       at java.net.SocketInputStream.read(SocketInputStream.java:121) 
       at java.io.BufferedInputStream.fill(BufferedInputStream.java:235) 
       at java.io.BufferedInputStream.read1(BufferedInputStream.java:275) 
       at java.io.BufferedInputStream.read(BufferedInputStream.java:334) 
       at org.bson.io.Bits.readFully(Bits.java:48) 
       at org.bson.io.Bits.readFully(Bits.java:35) 
       at org.bson.io.Bits.readFully(Bits.java:30) 
       at com.mongodb.Response.<init>(Response.java:42) 
       at com.mongodb.DBPort$1.execute(DBPort.java:141) 
       at com.mongodb.DBPort$1.execute(DBPort.java:135) 
       at com.mongodb.DBPort.doOperation(DBPort.java:164) 
       at com.mongodb.DBPort.call(DBPort.java:135) 
       at com.mongodb.DBTCPConnector.innerCall(DBTCPConnector.java:292) 

According to MONGO document I've reduced the tcp_keepalive_time to 300 seconds(default ws 7200 seconds) at the client machine from where the connection have been made to the MONGO REPLICA set.And also changed the values tcp_keepalive_intvl and tcp_keepalive_probes to increase the TCP acknowledgement frequency and also applied the retry logic but still getting the problem in that environment.This problem is particularly happening in that environment not at QA or UAT. Don't know why? And more over why this problem is occurring with MONGO driver not with JDBC driver for RDBMS? Please help me as things are going worse day by day as we don't have to say to the client as why it is happening?

Jeff Yemin

unread,
Jul 15, 2014, 11:53:28 AM7/15/14
to mongod...@googlegroups.com
By default, the driver does not enable TCP keep-alive on the sockets it creates.  You have to enable it explicitly using the MongoClientOptions.Builder.html#socketKeepAlive method.  Does your application do that?


Regards,
Jeff


--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
 
For other MongoDB technical support options, see: http://www.mongodb.org/about/support/.
---
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.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at http://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/1ad27e93-d7dd-4764-8a4b-bcedb22828b7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jeff Yemin

unread,
Jul 15, 2014, 11:55:14 AM7/15/14
to mongod...@googlegroups.com
By default, the driver does not enable TCP keep-alive on the sockets it creates.  You have to enable it explicitly using the MongoClientOptions.Builder.html#socketKeepAlive method.  Does your application do that?


Regards,
Jeff

Amarnath Bhattacharya

unread,
Jul 16, 2014, 2:40:08 AM7/16/14
to mongod...@googlegroups.com
Yes it has.Here I'm attaching the SPRING settings snippets for the MONGO replication set:

<!-- Replica set configuration with MONGO options -->
<mongo:mongo id="replSet" replica-set="${mongo.repl.set.hosts}">
<mongo:options auto-connect-retry="true"
write-number="${mongo.db.options.write.number}" 
connections-per-host="${mongo.db.options.connection.per.host}"
threads-allowed-to-block-for-connection-multiplier="${mongo.db.options.threads.allowed.to.block}"
socket-keep-alive="${mongo.db.options.socket.keep.alive}"
socket-timeout="${mongo.db.options.socket.timeout}" 
write-fsync="${mongo.db.options.write.fsync}"
slave-ok="${mongo.read.from.slave}" />
</mongo:mongo>

and the corresponding properties file snippets:

###############################################################################
############ The MONGO DB database properties for replica set #################
###############################################################################
#The database name for CMS administration

#The database name for CMS content

#The database name for CMS folder 

#The collection name for the CMS content

#The User name and password for the MONGO DB
mongo.db.user.password=dppuser

#The write number or w option of MONGO.
mongo.db.options.write.number=1

#Number of connections per host.
mongo.db.options.connection.per.host=10

#The number of threads allowed to block for connection multiplier.
mongo.db.options.threads.allowed.to.block=5

#SOCKET keep alive time through fire wall.
mongo.db.options.socket.keep.alive=true

#SOCKET time out in millisecond.Here 300000 means 5 minutes.
mongo.db.options.socket.timeout=300000

#Flush the write operation on disk and then only acknowledge.
mongo.db.options.write.fsync=true

#Replica set participants.A comma separated values in the form of <host>:<port>
mongo.repl.set.hosts=localhost:28017,localhost:29017

#Enable this flag in replica set environment.
mongo.read.from.slave=true
Reply all
Reply to author
Forward
0 new messages