4

我正在使用 MongoDb,在从数据库读取记录时遇到问题。我能够将它们放在游标中,但是当我尝试使用 cursor.hasNext() 从游标中获取记录时,它给了我以下异常:

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)

也许我正面临这个问题,因为我的数据不断增加,所以我在游标中获得了更多的记录。我正在访问的数据库也在远程机器上。

请在这方面需要帮助。

谢谢!

4

1 回答 1

4

根据您所描述的,我想我在 PHP 中遇到过这个问题,因为该集合同时遇到了繁重的读取负载和写入负载。一些读取可能会起作用,但最终它们会开始超时。我的光标超时设置为 30 秒,这不是问题,因为我们使用 Mongo 进行后端数据挖掘/处理。我们已经能够通过对我们的服务器进行分片来在一定程度上缓解这个问题,但这个问题仍然经常出现。我认为这源于大多数 Mongo 都是单线程的,因此繁重的负载变成了一个长的处理队列,最终变成了超时。

我还会检查并确保您的 RAM 没有被索引数据或实际数据填满 - 如果是这种情况,Mongo 必须去硬盘驱动器获取该数据,这比从内存中读取要慢 80 倍以上. db.getStats()您可以通过为有问题的数据库运行来查看您的索引/数据足迹。

于 2011-04-03T06:43:16.707 回答