Reputation: 4296
I have some mongodb questions regading slow queries. Following shows 2 entries from my mongodb log. I'm using mongodb version 2.4.12. In this case those queries are taking high response time. (2354ms and 1173ms accordingly). I know 1st one is a READ query and second one is an UPDATE query.
1st Query
Mon Sep 01 11:00:01.171 [conn11431867] query myapp.User query: { clientId: 40000 } ntoreturn:0 ntoskip:0 nscanned:278045 keyUpdates:0 numYields: 2 locks(micros) r:4187970 nreturned:18 reslen:14091 2354ms
2nd Query
Mon Sep 01 22:10:00.394 [conn11374746] update myapp.User query: { _id: ObjectId('5789999e4b06d0f3aeeb947') } update: { _id: ObjectId('5789999e4b06d0f3aeeb947'), className: "com.myapp.domain.User", firstName: "Amila", lastName: "Iddamalgoda", userId: 10001000, loginId: "amilai", emailAddress: "[email protected]", clientId: 40000 } idhack:1 nupdated:1 keyUpdates:0 locks(micros) w:189 1592ms
Could anyone please provide answers to following questions ? Thanks. Appreciate a lot.
1.) I'm using sharding as well. And for this User collection index is set for 'userId'. What can be the root causes for this slow response time from mongo? (2354ms and 1173ms)
2.) In the first query log, what is query: { clientId: 40000 } means ? is mongo finding a User using clientId key ? And nscannedObjects ==> No. of document scanned. But what is 'r' and 'nreturned' and 'reslen' means ?
3.) I know mongo is using multi-granularity locking. But in this case is this response time is a result of write lock ?
4.) I need to break down what is showing in the second query (update query). Is it reading from ObjectId and updating individual fields or ? what's going there ?
Upvotes: 0
Views: 2422
Reputation: 8639
Answer your question one by one:
{ clientId: 40000 }
. The query statement of this log is db.User.find({ clientId: 40000 })
. And your index is on userId, this query need index on clientId to speed up.For operations that require more than one lock, like those that lock the local database to update the oplog, this value may be longer than the total length of the operation (i.e. millis.)
Sum up, consider creating an index on clientId.
Upvotes: 1