How can I check mongodb query performance without cache How can I check mongodb query performance without cache mongodb mongodb

How can I check mongodb query performance without cache


I guess you can not stop Mongo from preparing the query plan (that's how mongo works).So, Before query stats..1. Clear the plan cache of all collections by

>db.colllction_name.getPlanCache().clear()
  1. Record the slow queries with Profiler (see mongo docs),
  2. work on query to optimize it,
  3. clear the cache again, and check the query performance again.


When you are first running the query, the data set is memory mapped, but has not been paged into actual memory, see Caching on the MongoDB site. So, the OS has to page that data set into memory and then you get your query run and result.

Because you are paging in from the disk (slow) into RAM (fast) the initial run is slow, and then, unless you have memory pressure, that data will stay in RAM and all of your subsequent queries on that data set will be fast.

This is how MongoDB is designed to function, the process of loading your data set into memory is often called "warming up" the database and it is only after that warming up (in your case the first query) that you get the true performance.

It is worth noting that your initial query still seems to take a very long time to return. You should make sure it is using indexes effectively. The best place to start in that investigation is the explain() page.


You can use db.collection.getPlanCache().clear() to remove all cached query plans for a collection.

https://docs.mongodb.com/v3.2/reference/method/PlanCache.clear/