Skip to content
LESSON 18 / 50Advancedwiredtiger

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.

Interactive Engine Simulator

WiredTiger Storage Engine: Cache, Journal & Checkpoints

Simulate RAM page states, dirty page eviction thresholds, WAL journaling, and 60-second checkpoint disk flushes.

Dirty Page Ratio
50%
Eviction triggers at 80%
Journal WAL LSN
#1048
Flushed every 100ms
Last Checkpoint
18s ago
Default period: 60s
Node State
HEALTHY
WiredTiger Engine
1. RAM Cache (Volatile)4 Pages
p-1users: [u1..u20]
CLEAN
p-2orders: [o101..o150]
DIRTY
p-3products: [p1..p50]
CLEAN
p-4users: [u21..u40]
DIRTY
2. Journal (WAL Ring Buffer)fsync 100ms
Active Journal File:WiredTigerLog.0000000001
Current LSN:#1048
Persistence guarantee:Write Concern j:true
Sequential append-only log enables instant crash recovery by replaying changes between last checkpoint and current LSN.
3. Disk Storage (.wt B-Trees)Checkpointed
Data Tables:collection-*.wt
Index Tables:index-*.wt
Root Pointer:WiredTiger.turtle
Disk files store B-Tree pages with Snappy / zlib compression. Only updated during checkpoint flush or heavy eviction.
ENGINE_LOG:Engine initialized. WiredTiger cache allocated (50% RAM minus 1GB).

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.

Sample BSON Documents:
Collection: db.serverStatus.wiredTiger.cache
{
  "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

Step 1: Check eviction worker health and page eviction rates
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"]);
Non-zero "pages evicted by application threads" indicates dangerous cache exhaustion.

5. Critical Engineering Rules

Rule / ConstraintUnderlying 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"];
Production Warning: When client threads are forced to evict, database p99 latency spikes drastically.

7. Architectural Trade-offs

Advantages
  • •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
Disadvantages & Gotchas
  • •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

Q1: What is the significance of the "pages evicted by application threads" metric in WiredTiger serverStatus?

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?