简体   繁体   中英

How to read mongodb log?

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: "test@test.com", 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 ?

Answer your question one by one:

  1. Your query scanned 278045 docs to find out 18 results. This may well be the root cause.
  2. query: { clientId: 40000 } means your query object is exactly { 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.
  3. In general situations, lock time is shorter than response time. But

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 (ie millis.)

  1. Have no idea.

Sum up, consider creating an index on clientId .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM