What is the WiredTiger cache and how does it affect performance?

Answer

The WiredTiger internal cache is an in-memory buffer pool that holds frequently accessed data and indexes, reducing disk I/O. Understanding and tuning it is critical for MongoDB performance. Default size: max(50% of (total RAM - 1GB), 256MB). On a 16GB server: (16-1) × 0.5 = 7.5GB. Cache structure: stores B-tree pages from data and index files. WiredTiger's cache uses different compression than disk — data in cache is uncompressed for faster access. Disk has zstd/snappy/zlib; cache is uncompressed. This means the cache holds 3-5x less data than the compressed disk representation. Working set: the portion of data actively accessed. Performance degrades sharply when working set exceeds cache size — frequent evictions require disk reads (I/O bottleneck). Monitor: if evictions are high and disk I/O is high, the cache is too small. Configuration: storage.wiredTiger.engineConfig.cacheSizeGB: 10 in mongod.conf. Don't set more than 70% of RAM — leave memory for OS page cache, aggregation sorting, connection buffers. OS page cache: WiredTiger intentionally leaves room for OS page cache, which also buffers database files. Total effective cache = WiredTiger cache + OS page cache. Monitoring: db.serverStatus().wiredTiger.cache — look at "bytes currently in the cache," "tracked dirty bytes in the cache," "pages evicted by application threads" (high = memory pressure). Eviction: WiredTiger evicts dirty pages (flushing to disk) and clean pages (just removing from cache) when cache is under pressure. Background eviction threads run proactively; foreground eviction (application threads help) indicates severe memory pressure.