Peek into WiredTiger Cache

WiredTiger is the default storage engine starting in MongoDB v3.2.  In the diagram below, the red arrows show the flow of data through compression/decompression steps among the WiredTiger cache, file system cache and data files.

Ideally, if all data, including indexes, can fit into the WiredTiger cache, accessing documents would be more efficient than having to access disk files frequently.  In reality, memory resources are shared to support other tasks such as file system cache, user connections, and database operations, for example, sorting.  At startup, if the WiredTiger cache size is not defined, the maximum memory allocated to the WiredTiger cache size is about a little less than 50% of the RAM.

When experiencing performance degradation, users always intend to tune the WiredTiger cache size.  It is recommended to use the default value unless you have a small working set that can possibly fit into WiredTiger cache or the compressed data size can fit into file system cache.  In most production environments I have seen, the amount of data is much greater than RAM can contain and often allocating most memory resources to a component does not improve performance. 

WiredTiger Cache

Realizing altering WiredTiger cache size does not improve performance, the next question raised is a witch hunt on what data is flooding the WiredTiger cache.  Keyhole provides a way to view data and indexes in the WiredTiger cache.  First, connect Keyhole to a mongod server, for example:

keyhole -wt "mongodb://user:password@localhost:27017/?connect=direct"

Open http://hostname:5408/wt in a browser and four charts showing data inside the WiredTiger cache are displayed as below.  The animation refreshes every 5 seconds.


Popular posts from this blog

Build and Download Keyhole

MongoPush - Push-Based MongoDB Atlas Migration Tool

Survey Your Mongo Land