Search code examples
mongodbwiredtiger

How to detect if my query result is retrieved from WiredTiger cache?


I'm using Mongo version 3.4, storage engine is WiredTiger. As the document says, Mongo does use cache for working set that fits in RAM.

So my questions are

  1. Is there any way I can check if my query result is served from cache or not ?
  2. What if my working set is larger than RAM ? Would Mongo clear the cache, or would it evict some data ?
  3. Any suggestion for good resources to learn about Mongo caching mechanism

Solution

  • The WiredTiger cache is a generic term for memory reserved for use by WiredTiger. This memory contains uncompressed collection data, indexes, "dirty" content (modified documents), etc.

    To answer your questions:

    Is there any way I can check if my query result is served from cache or not ?

    Any query will result in WiredTiger loading the document from disk into its part of memory (the so-called "cache") in an uncompressed form. Therefore all query replies are served from the "cache".

    What if my working set is larger than RAM ? Would Mongo clear the cache, or would it evict some data ?

    It will evict data from the cache as necessary. If the data that needs to be evicted are "dirty", it will also need to be written to disk as part of the eviction process.

    Any suggestion for good resources to learn about Mongo caching mechanism

    There are some general description of it in MongoDB documentation:

    For more in-depth documentation, please see the WiredTiger documentation.