In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
MongoDB query timeout exception how to solve, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.
Aggregating a collection of more than a million records.
DBObject match= (DBObject) JSON.parse ("{$match: {logType: {'$in': [5 sum':1 9]}}"); DBObject group= (DBObject) JSON.parse ("{$group: {'_ id':'$domainUrl','count': {'$sum':1}}"); AggregationOutput output = logCollection.aggregate (match,group)
Occasional Read timed out exceptions occur.
Com.mongodb.MongoException$Network: Read operation to server / 192.168.10.202 failed on database adLogTable at com.mongodb.DBTCPConnector.innerCall (DBTCPConnector.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 (SocketInputStream.java:152)
After many tests, it is found that the average time of performing an aggregation is 5s, and an error will be reported when it exceeds 5s!
Then view the configuration information of MongoDB:
Socket-timeout= "5000" / / 5s
The default configuration of socket-timeout is 0, which means there is no limit.
There is no time-out limit, and the problem with the system is not easy to find. A reasonable time-out should be given according to the actual situation.
After several tests, it was found that the maximum execution time was 6 seconds, and the timeout time was set to 10000.
Socket-timeout= "10000" / / 10s
Note: when MongoDB integrates with Spring, if you want to configure multiple MongDB sources, only one configuration will be enabled.
Parameter configuration information should be stored in the properties file.
Get configuration parameters through Java API
DBCollection logCollection = mongoTemplate.getCollection (collName); MongoOptions mongoOptions = logCollection.getDB (). GetMongo (). GetMongoOptions (); System.out.println (mongoOptions.getSocketTimeout ())
* one thing: the difference between ConnectionTimeOut and SocketTimeOut:
A complete request consists of three phases:
Establish a connection
Data transmission
Disconnect
If the request to establish a connection with the server (in this case, the database) takes longer than ConnectionTimeOut, ConnectionTimeOutException will be thrown, that is, the server connection timed out and the connection was not established within the specified time.
If the connection to the server is successful, the data transfer begins.
If the server takes too long to process the data and exceeds the SocketTimeOut, the SocketTimeOutExceptin will be thrown, that is, the server response timed out and the server did not return the data to the client within the specified time.
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.