Cursor.hasNext() stuck?

644 views
Skip to first unread message

oferfort

unread,
May 5, 2011, 4:32:52 PM5/5/11
to mongodb-user
Hey all,
i have a sharded collection and i'm querying by _id.
Usually i'm using findOne and it works ok, but today i decided to see
if find($in, {_id: array}) would be any better.
After a few tests i realized that for a small amount of ids findOne
for each is actually faster, but for a few hundreds or thousands of
ids, the $in method is quicker.

I was happy for a while, untill i started getting stuck, and thread
dump showed all my threads stuck on cursor.hasNext()

"Thread-786" prio=5 id=808 RUNNABLE
java.net.SocketInputStream.socketRead0(Native Method)
java.net.SocketInputStream.read(SocketInputStream.java:129)
java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
java.io.BufferedInputStream.read1(BufferedInputStream.java:
258)
java.io.BufferedInputStream.read(BufferedInputStream.java:317)
org.bson.io.Bits.readFully(Bits.java:35)
org.bson.io.Bits.readFully(Bits.java:28)
com.mongodb.Response.<init>(Response.java:35)
com.mongodb.DBPort.go(DBPort.java:110)
com.mongodb.DBPort.go(DBPort.java:75)
com.mongodb.DBPort.call(DBPort.java:65)
com.mongodb.DBTCPConnector.call(DBTCPConnector.java:201)
com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:
295)
com.mongodb.DBCursor._check(DBCursor.java:354)
com.mongodb.DBCursor._hasNext(DBCursor.java:484)
com.mongodb.DBCursor.hasNext(DBCursor.java:509)

My code is pretty simple:
BasicDBObject query = new BasicDBObject();
query.put("_id", new BasicDBObject("$in", ids));
DBCursor result = db.getCollection(table).find(new
BasicDBObject(query));

while (result.hasNext())
{
DBObject object = result.next();
objects.put(object.get("_id"), object.toMap());
}

i'm using mongo 1.8.1 and a 2.5.3 java driver.
thanks for any insights

ofer

Scott Hernandez

unread,
May 5, 2011, 6:57:31 PM5/5/11
to mongod...@googlegroups.com
Can you provide the full exception? How many ids are in that query?

This is just a guess but I suspect it just takes a long time to get any results from the query. It is not until the first next() that the query is actually run on the server. Can you run db.currentOP() from the javascript during the pause and post the results?


--
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com.
To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.


Ofer Fort

unread,
May 5, 2011, 11:21:35 PM5/5/11
to mongod...@googlegroups.com
On Fri, May 6, 2011 at 1:57 AM, Scott Hernandez <scotthe...@gmail.com> wrote:
Can you provide the full exception? How many ids are in that query?

This is the full stack trace, before that was my call to  result.next();

This is just a guess but I suspect it just takes a long time to get any results from the query. It is not until the first next() that the query is actually run on the server. Can you run db.currentOP() from the javascript during the pause and post the results?

The time that my application was stuck was about 30 minutes, before i had to restart it, so i'm guessing it's not just taking long. I've disabled this for now, since this was not usable to me for now. I'll to test it again tomorrow and see if db.currentOp() will show anything interesting.
thanks

Scott Hernandez

unread,
May 30, 2011, 9:14:43 PM5/30/11
to mongod...@googlegroups.com
On Thu, May 5, 2011 at 8:21 PM, Ofer Fort <of...@tra.cx> wrote:


On Fri, May 6, 2011 at 1:57 AM, Scott Hernandez <scotthe...@gmail.com> wrote:
Can you provide the full exception? How many ids are in that query?

This is the full stack trace, before that was my call to  result.next();

The 2.6 driver has been released, could you see if that makes a difference?
 

This is just a guess but I suspect it just takes a long time to get any results from the query. It is not until the first next() that the query is actually run on the server. Can you run db.currentOP() from the javascript during the pause and post the results?

The time that my application was stuck was about 30 minutes, before i had to restart it, so i'm guessing it's not just taking long. I've disabled this for now, since this was not usable to me for now. I'll to test it again tomorrow and see if db.currentOp() will show anything interesting.

Did anything turn up?

Richard Filippi

unread,
Aug 28, 2013, 11:51:30 AM8/28/13
to mongod...@googlegroups.com
I realise it's an old thread, but we've been googling around a similar problem and were wondering if anyone else came up with anything here ?

We are observing the same behaviour, perhaps with a slow running query, but what is confusing us is by the stack trace is why does the configured socket timeout not take effect ? 

We have SocketTimeout configured to 15s and would expect that if the _hasNext() method is running a slow query that nothing would be returned from the server until some results were available and so a query taking longer than 15s to execute would throw an exception ?  
Reply all
Reply to author
Forward
0 new messages