Eviction Server Threads & Cache Eviction Triggers
WiredTiger utilizes autonomous background eviction worker threads to continuously reclaim cache memory, pacing clean page drops and dirty page flushes.
WiredTiger Storage Engine: Cache, Journal & Checkpoints
Simulate RAM page states, dirty page eviction thresholds, WAL journaling, and 60-second checkpoint disk flushes.
1. Formal Definition & Architecture Intent
The WiredTiger Eviction Server is an autonomous background subsystem consisting of multiple eviction worker threads. Its responsibility is to monitor cache utilization and ensure that available cache memory never drops below safe operating margins by discarding clean pages and writing dirty pages to disk.
2. Explain Like I'm 5 (Mental Model)
Imagine a busy restaurant dining room with limited tables. The busboys (eviction threads) constantly clear empty plates (clean pages) and wipe down dirty tables (dirty pages) so new guests (queries) never have to wait outside.
3. Real-World Architecture Example
Eviction server pacing under high memory load.
{
"eviction worker thread evicting pages": 4,
"pages evicted by application threads": 0,
"maximum page size at eviction": 65536
}Zero pages evicted by application threads proves that background eviction workers are keeping pace with write throughput.
4. MQL Implementation Steps
const c = db.serverStatus().wiredTiger.cache;
print("Evicted clean: " + c["unmodified pages evicted"]);
print("Evicted dirty: " + c["modified pages evicted"]);
print("Evicted by app threads: " + c["pages evicted by application threads"]);5. Critical Engineering Rules
| Rule / Constraint | Underlying Reason & Impact |
|---|---|
| Eviction Trigger (80%) | Background eviction begins gently when cache exceeds 80% capacity. |
| Aggressive Eviction (95%) | Background threads spawn extra workers and evict aggressively. |
| App Thread Stalls (95%+ or 20% dirty) | Client application queries stall and are forced to perform disk eviction themselves. |
6. Deep Dive: The LRU (Least Recently Used) Hazard Pointer Algorithm
WiredTiger does not use a naive global LRU linked list, which causes massive lock contention on multi-core servers. Instead, eviction threads walk random B-Tree branches using hazard pointers, scoring pages based on read generation timestamps and dirty status, selecting cold candidates for eviction without blocking active worker threads.
// Server status metrics tracking eviction server: db.serverStatus().wiredTiger.cache["eviction server passes through the cache"];
7. Architectural Trade-offs
- •Decouples query execution from physical disk flush routines under normal loads
- •Hazard-pointer scanning avoids global lock bottlenecks on 64+ CPU core servers
- •Dynamic scaling of eviction workers matches incoming write bursts
- •Consumes significant background CPU during heavy random write workloads
- •Can evict warm data prematurely if the working set exceeds physical cache allocation
8. Technical Interview Questions
Under normal operation, this metric should be zero because dedicated background eviction worker threads handle all page evictions. If this value is greater than zero, it means background eviction workers could not keep up with write volume, forcing incoming client application threads to synchronously write dirty pages to disk, causing severe latency spikes.
9. Staff-Level Ready Answer
"WiredTiger maintains background eviction worker threads that monitor cache thresholds (80% full or 5% dirty). They scan B-Trees using hazard pointers to evict cold clean pages and write dirty pages to disk. If cache reaches 95% full or 20% dirty, client threads are forced to evict, causing application latency spikes."
10. Quick Knowledge Check
Which condition causes incoming application client requests to stall and perform page eviction themselves?