Site icon Database Tutorials

Slow queries on MongoDB

 

During a typical revision of mongod’s logs, we could find slow queries, by default, those queries that take more >100ms. You can change this time with –slowms <integer> parameter when you launch a mongod process or using a configuration file.

This is an expample of log message:

2018-07-02T12:26:24.580-0500 I COMMAND [conn11186210] command test.CARcommand: getMore { getMore: 164459457945, collection: “CAR” } planSummary: IXSCAN { _id: 1 } cursorid:164459457945 keysExamined:6488 docsExamined:6488 keyUpdates:0 writeConflicts:0 numYields:50 nreturned:6488 reslen:4194880 locks:{ Global: { acquireCount: { r: 102 } }, MMAPV1Journal: { acquireCount: { r: 102 } }, Database: { acquireCount: { r: 51 } }, Collection: { acquireCount: { R: 51 }, acquireWaitCount: { R: 51 }, timeAcquiringMicros: { R: 140362206 } } } protocol:op_query 140378ms

Components associated:

Conclusion

In this expample the getmore command takes 140.378 seconds to resolve, the root cause are locks.

If keysExamined is much higher than nreturned, the database is scanning many index keys to find the result documents. Consider creating or adjusting indexes to improve query performance. In this example isn’t the case.

As you can see, this MongoDB installation is using MMAPv1 storage engine, I recommend using WiredTiger Storage Engine in case of multiple clients want to modify different documents of a collection at the same time.

Exit mobile version