MongoDB query timeout exception SocketTimeoutException
MongoDB query timeout exception SocketTimeoutException
Aggregate a collection of more than one million records.
DBObject match = (DBObject) JSON. parse ("{$ match: {logType: {'$ in': [5, 9] }}}");
DBObject group = (DBObject) JSON. parse ("{$ group: {'_ id':' $ domainurl', 'Count': {'$ Sum': 1 }}}");
AggregationOutput output = logCollection. aggregate (match, group );
Occasionally, a Read timed out exception occurs.
Com. mongodb. MongoException $ Network: Read operation to server/192.168.10.202: 27017 failed on database adLogTable
At com. mongodb. DBTCPConnector. innerCall (dbtcpconne. java: 253)
At com. mongodb. DB. command (DB. java: 261)
At com. mongodb. DB. command (DB. java: 243 )...
Caused by: java.net. SocketTimeoutException: Read timed out
At java.net. SocketInputStream. socketRead0 (Native Method)
At java.net. SocketInputStream. read (fig. java: 152)
After multiple tests, it is found that the average time for performing an aggregation operation is 5 s. If the time exceeds 5 s, an error is reported!
Then, view the MongoDB configuration information:
Socket-timeout = "5000"/5S
The default socket-timeout configuration is 0, that is, there is no limit.
There is no timeout limit, and it is not easy to find out a problem in the system. A reasonable timeout time should be provided according to the actual situation.
Multiple tests show that the maximum execution time is 6 seconds, and the timeout time is set to 10000.
Socket-timeout = "10000" // 10 s
Note: When MongoDB is integrated with Spring, if you want to configure multiple MongDB sources, only the last Configuration.
The parameter configuration information should be stored in the properties file.
Threads-allowed-to-block-for-connection-Multi-plier = "100"
Connect-timeout = "1000"
Max-wait-time = "1000"
Auto-connect-retry = "true"
Socket-keep-alive = "true"
Socket-timeout = "10000"
Slave-OK = "true"
Write-number = "1"
Write-timeout = "0"
Write-fsync = "true"/>
Get configuration parameters through Java API
DBCollection logCollection = custom template. getCollection (collName );
Optional options exist Options = logCollection. getDB (). getMongo (). getmetadata options ();
System. out. println (gradient options. getSocketTimeout ());
Last point: ConnectionTimeOut and SocketTimeOut:
A complete request consists of three phases: 1. Establish a connection 2. Data Transmission 3. Disconnect
If the connection time for a server (database) request exceeds ConnectionTimeOut, ConnectionTimeOutException is thrown, that is, the server connection times out and no connection is established within the specified time.
If the connection to the server is successful, data transmission starts.
If the time used by the server to process data exceeds SocketTimeOut, SocketTimeOutExceptin is thrown. That is, the server response times out and the server does not return data to the client within the specified time.
CentOS compilation and installation of php extensions for MongoDB and mongoDB
CentOS 6 install MongoDB and server configuration using yum
Install MongoDB2.4.3 in Ubuntu 13.04
MongoDB beginners must read (both concepts and practices)
MongoDB Installation Guide for Ubunu 14.04
MongoDB authoritative Guide (The Definitive Guide) in English [PDF]
Nagios monitoring MongoDB sharded cluster service practice
Build MongoDB Service Based on CentOS 6.5 Operating System
MongoDB details: click here
MongoDB: click here