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 either:
- 50% of RAM minus 1 GB
- 256 MB
This means if our server has 8 GB RAM:
max(3GB , 256 MB) = WiredTiger will use 3GB of RAM
And if our server has 2,512 MB RAM:
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
Or from the command line using the following:
--wiredTigerCacheSizeGB
Apart from the WiredTiger internal cache, which is uncompressed for higher performance, MongoDB also uses the filesystem cache, which 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 and 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.