MongoDB primary stalls and throughput collapses when WiredTiger cache reaches high utilization during sustained bulk inserts
Environment
MongoDB 5.0 replica set (3 members) on Ubuntu 20.04 servers with 32GB RAM, WiredTiger cache configured to 60% of RAM (~18GB), NVMe-backed data directories; application performs sustained bulk inserts in batches of 10k documents.
Symptoms
Under sustained bulk insert load, the primary's insert throughput drops sharply after several minutes and clients observe increased write latency and occasional 'WriteConflict' errors. Server status shows WiredTiger cache utilization nearing the configured maximum; page eviction rates spike and fsync/write stall times increase. Secondary nodes fall behind replication as the primary struggles to keep up.
Observations
mongostat shows WT cache occupancy climbing to ~99% of the configured cache and eviction activity rising. mongod log contains repeated entries about 'WT cache exceeded target' and 'waiting for cache to be freed' followed by increased checkpoint times. iostat shows high write amplification and increased disk latency during stall periods. After pausing traffic the cache drains and throughput recovers, but the pattern repeats under resumed load.
Already attempted
Adjusted WiredTiger cache size up and down in small increments (restarted mongod to apply), which delayed but did not eliminate stalls. Reduced bulk insert batch size and observed smoother behavior but lower overall throughput. Enabled diagnostic log verbosity for WT and collected serverStatus metrics. Considered increasing RAM but constrained by server hardware. Implemented write-concern w:1 for bulk loads temporarily to reduce replication pressure (acceptable for test loads only).
Question
What are safe configuration changes and operational mitigations to prevent WiredTiger cache saturation and the resulting write stalls during large bulk insert bursts, and how should I instrument and tune the system to find a sustainable balance between throughput and eviction pressure?
Verified community troubleshooting
No answers yet..
Incident analysis
Most likely causes
Summary
Suggested Fixes
Continue troubleshooting
Related troubles
Matched from the title, description and tags