MongoDB getmore on collection is very slow
I am trying to debug a high cpu issue on a MongoDB instance. We have two r3.large AWS shards. There are not many page errors compared to the number of options.
The system profile shows tons of getmore entries as shown below. Please help me find out what is causing getmore to be very slow.
{
"op" : "getmore",
"ns" : "mydb.mycollection",
"cursorid" : 74493486271,
"ntoreturn" : 0,
"keyUpdates" : 0,
"numYield" : 7,
"lockStats" : {
"timeLockedMicros" : {
"r" : NumberLong(16140),
"w" : NumberLong(0)
},
"timeAcquiringMicros" : {
"r" : NumberLong(6458801),
"w" : NumberLong(294321)
}
},
"nreturned" : 120,
"responseLength" : 13100,
"millis" : 6304,
"execStats" : {
},
"ts" : ISODate("2015-06-16T14:20:39.886Z"),
"client" : "1.5.1.3",
"allUsers" : [ ],
"user" : ""
}
+3
source to share
1 answer
Answering my question, it might help someone else.
- Enabled more logging on high CPU
db.adminCommand( { setParameter: 1, logLevel: 1 } )
, after reset to logLevel: 0 (default). - The log then found a summary request with 0ms, but immediately after that, getmore writes from 5 to 6 seconds.
-
An aggregate query has
cursor: { batchSize: 0 }
an initial batch size of zero. This way, the request comes back quickly. But when the application started to iterate through the cursor, then getmore is logged, and this record does not contain any details of the request.Fixing the aggregation of the $ match query to exploit the resolved issue.
+3
source to share