WiredTiger is significantly different to MMAPv1 in how it uses RAM. MMAPv1 is essentially using the underlying operating system's filesystem cache to page data from disk to memory and vice versa.
WiredTiger, on the contrary, introduces the new concept of the WiredTiger internal cache.
The WiredTiger internal cache is, by default, the larger of the following:
- 50% of RAM minus 1 GB
- 256 MB
This means if our server has 8 GB RAM we will get the following:
max(3 GB , 256 MB) = WiredTiger will use 3 GB of RAM
And if our server has 2,512 MB RAM we will get the following:
max(256 MB, 256 MB) = WiredTiger will use 256 MB of RAM
Essentially, for any server that has less than 2,512 MB RAM, WiredTiger will use 256 MB for its internal cache.
We can change the size of the WiredTiger internal cache by setting the following:
storage.wiredTiger.engineConfig.cacheSizeGB
We can also do this from the command line using the following:
--wiredTigerCacheSizeGB
Apart from the WiredTiger internal cache that is uncompressed for higher performance, MongoDB also uses the filesystem cache that is compressed, just like MMAPv1, and will end up using all available memory in most cases.
The WiredTiger internal cache can provide similar performance to in-memory storage. As such, it is important to grow it as much as possible.
We can achieve better performance when using WiredTiger with multi-core processors. This is also a big win compared to MMAPv1, which does not scale as well.