Mongo + Java + SocketTimeOut

I am using MongoDb and am having trouble reading records from the database. I can get them at the cursor, but when I try to get entries from the cursor using cursor.hasNext () this gives me the following exception:

com.mongodb.MongoInternalException: couldn't get next element at com.mongodb.DBCursor.hasNext(DBCursor.java:459) Caused by: java.net.SocketTimeoutException: Read timed out at java.net.SocketInputStream.socketRead0(Native Method) at java.net.SocketInputStream.read(SocketInputStream.java:146) 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:35) at org.bson.io.Bits.readFully(Bits.java:28) at com.mongodb.Response.<init>(Response.java:35) at com.mongodb.DBPort.go(DBPort.java:101) at com.mongodb.DBPort.go(DBPort.java:66) at com.mongodb.DBPort.call(DBPort.java:56) at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:211) at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:220) at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:220) at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:266) at com.mongodb.DBCursor._check(DBCursor.java:309) at com.mongodb.DBCursor._hasNext(DBCursor.java:431) at com.mongodb.DBCursor.hasNext(DBCursor.java:456) 

Perhaps I ran into this problem, as my data is constantly increasing, so I get more entries in the cursor. An accessible database is also located on the remote machine.

Please help us with this.

Thanks!

+4
source share
1 answer

Based on what you described, I think I ran into this problem in PHP when the collection is experiencing both a heavy read and load load. Some readings may work, but in the end they will start the countdown. My cursor timeout is set to 30 seconds, which is not a problem, since we use Mongo to develop / process backend data. We managed to alleviate the problem a bit by fining our servers, but the problem is still growing quite regularly. I think this is due to the fact that most of Mongo is single-threaded, and therefore heavy loading turns into a long processing queue, which eventually turns into timeouts.

I would also check and make sure that your RAM is not populated with index data or actual data - if so, Mongo must go to the hard drive to get this data, which is more than 80 times slower than reading from memory. You can see what your index / data is occupying by running db.getStats() for a given database.

+4
source

Source: https://habr.com/ru/post/1345702/


All Articles