I am using MongoDb and I am facing problems while reading the records from the DB. I am able to get them in the cursor but when I try to get the records from the cursor using cursor.hasNext() it gives me 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)
Maybe I am facing this issue as my data is continously increasing so I am getting more number of records in the cursor. Also the database I am accessing is on remote machine.
Please need help on this.
Thanks!
Based on what you've described, I think I've experienced this issue in PHP when the collection is experiencing both heavy read load and write load. Some reads might work but eventually they'll start timing out. My cursor timeout is set to 30s, which isn't an issue since we use Mongo for backend data mining/processing. We've been able to mitigate the issue somewhat by sharding our servers, but the issue still crops up fairly regularly. I think this stems from the fact that most of Mongo is single-threaded and so a heavy load turns into a long processing queue which eventually turns into timeouts.
I'd also check and make sure your RAM isn't getting filled up by index data or actual data - if that's the case, Mongo has to go to the hard drive to get that data and that is over 80x slower than reading from memory. You can see what your index/data footprint is by running db.getStats()
for the database in question.
精彩评论