MongoDb Java驱动程序 - MongoException $ Network:对服务器localhost:27017的读操作失败

时间:2015-05-22 12:47:16

标签: mongodb mongo-java-driver

我们在上周间歇性地开始出现以下错误。到目前为止,我们无法将此问题追溯到任何特定的问题。有问题的查询是对具有大约400k对象的集合的聚合。我们为不同的客户运行相同的应用程序,它开始发生在已经超过400k标记的客户端。我直接运行查询,大约需要1.5秒。 当我们迭代另一个聚合的结果时,发生了同样的异常:

DBCursor cursor = db.cMD.find([colaborador: [$in: listP], data: data], [colab: 1, _id: 0])
def listW = []
while (cursor.hasNext()) //Exception happened here
{ def resultMap = cursor.next().toMap() listW.add(resultMap.colab) }
2015-05-20 14:03:43,511 [quartzScheduler_Worker-6] ERROR listeners.ExceptionPrinterJobListener - Exception occurred in job: Grails Job
org.quartz.JobExecutionException: com.mongodb.MongoException$Network: Read operation to server localhost:27017 failed on database application1 [See nested exception: com.mongodb.MongoException$Network: Read operation to server localhost:27017 failed on database application1]
at grails.plugins.quartz.GrailsJobFactory$GrailsJob.execute(GrailsJobFactory.java:111)
at grails.plugins.quartz.QuartzDisplayJob.execute(QuartzDisplayJob.groovy:27)
at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)
Caused by: com.mongodb.MongoException$Network: Read operation to server localhost:27017 failed on database application1
at com.mongodb.DBTCPConnector.innerCall(DBTCPConnector.java:300)
at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:271)
at com.mongodb.DBCollectionImpl.find(DBCollectionImpl.java:84)
at com.mongodb.DB.command(DB.java:317)
at com.mongodb.DB.command(DB.java:296)
at com.mongodb.DBCollectionImpl.aggregate(DBCollectionImpl.java:99)
at com.mongodb.DBCollection.aggregate(DBCollection.java:1571)
at com.gmongo.internal.Patcher._invoke(Patcher.groovy:49)
at com.gmongo.internal.Patcher$__patchInternal_closure1.doCall(Patcher.groovy:38)
at 
OUR APPLICATION CODE
at GrailsMelodyGrailsPlugin$_closure4_closure16_closure17.doCall(GrailsMelodyGrailsPlugin.groovy:184)
at 
OUR APPLICATION CODE
at grails.plugins.quartz.GrailsJobFactory$GrailsJob.execute(GrailsJobFactory.java:102)
... 3 more
Caused by: java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.read(SocketInputStream.java:152)
at java.net.SocketInputStream.read(SocketInputStream.java:122)
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:48)
at org.bson.io.Bits.readFully(Bits.java:35)
at org.bson.io.Bits.readFully(Bits.java:30)
at com.mongodb.Response.<init>(Response.java:42)
at com.mongodb.DBPort$1.execute(DBPort.java:141)
at com.mongodb.DBPort$1.execute(DBPort.java:135)
at com.mongodb.DBPort.doOperation(DBPort.java:164)
at com.mongodb.DBPort.call(DBPort.java:135)
at com.mongodb.DBTCPConnector.innerCall(DBTCPConnector.java:292)
... 16 more

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

我看到同样的消息做了一个更简单的db.collection.find(critera)。就我而言,我没有使用索引。一旦创建了一个,事情就会快得多,因此没有更多的超时