skip to content

A mongod shares a 64 GB host with a second process, and p99 latency climbs during a bulk load while application threads do eviction: how do you diagnose it from WiredTiger's cache statistics?

level: seniorimportance: should knowfreq 35%

answer

  1. turn counters into ratios of the maximum
  2. which trigger is being hit
  3. sample twice, compare rates
  4. the neighbour squeezes the other cache
  5. is storage keeping up

basics

~20 s

Compute dirty and used shares against maximum bytes configured: at 20% dirty or 95% used, application threads evict, and rising eviction counters confirm it. A write burst usually means slow storage or an over-fast load, rarely too small a cache.

solid answer

~40 s

First get the numbers for this host. The default cache is about 31.5 GB, computed from all the RAM regardless of the second process, so application threads evict at about 6.3 GB dirty, 3.2 GB of updates or 29.9 GB used. Then sample `db.serverStatus().wiredTiger.cache` twice and compute `tracked dirty bytes in the cache` and `bytes currently in the cache` over `maximum bytes configured`, plus the rates of `number of times dirty trigger was reached`, `page evict attempts by application threads` and `application thread time evicting (usecs)`. Dirty at its trigger during a load means writes outrun what eviction and the storage can drain. The second process mostly squeezes the filesystem cache and shares the disk. Slow the load or give it better storage first. More eviction threads help only if storage has headroom.

code

javascript · 8 lines
javascript
const c = db.serverStatus().wiredTiger.cache;
const max = c["maximum bytes configured"];
print("used %", 100 * c["bytes currently in the cache"] / max);
print("dirty %", 100 * c["tracked dirty bytes in the cache"] / max);
print("updates %", 100 * c["bytes allocated for updates"] / max);
print("dirty trigger hits", c["number of times dirty trigger was reached"]);
print("app evict attempts", c["page evict attempts by application threads"]);
print("app evict usecs", c["application thread time evicting (usecs)"]);

go deeper

for a junior

Recall that application threads doing eviction means a trigger was reached, and that serverStatus reports the numbers under wiredTiger.cache.

for a middle

Work out the trigger levels in gigabytes for the real cache size, and compute the used and dirty shares from their fields against the configured maximum.

for a senior

Separate the patterns: write-driven, read-driven, or not the cache at all. Check storage at the same timestamps, and name pacing the load as the first remedy.

for a principal

Turn the incident into rules: bulk loads have a pacing budget, co-tenants have an owner, and alerts watch sustained trigger rates rather than a momentary dirty percentage.

## Frame the numbers first A latency symptom during a bulk load plus application threads doing eviction suggests **WiredTiger's triggers are being hit**. WiredTiger is MongoDB's storage engine, and once a trigger is reached, the threads running your operations must also evict pages from its internal cache before they can continue. That work lands in some operations and not others, which is why p99 moves before the median. On a 64 GB host with the default, the internal cache is the larger of 256 MB and half of (RAM minus 1 GB), about 31.5 GB. The second process does not change that: the size is computed once at startup from the memory figure, and it knows nothing about a neighbour. | Threshold | Default | On 31.5 GB | |---|---|---| | `eviction_dirty_trigger` | 20% | 6.3 GB dirty | | `eviction_updates_trigger` | 10% | about 3.2 GB of updates | | `eviction_trigger` | 95% | about 29.9 GB in use | ## Reading `wiredTiger.cache` 1. **Confirm the size.** Read `maximum bytes configured`. If it is not about 31.5 GB, someone set an option, or the server sees different memory. 2. **Compute the three shares.** Divide `tracked dirty bytes in the cache`, `bytes allocated for updates` and `bytes currently in the cache` by the maximum. The dirty share against the maximum is the ratio the trigger uses, not dirty over bytes in use. `mongostat`'s `dirty` and `used` columns show the first and third. 3. **Find which trigger fires.** Sample twice and compare `number of times dirty trigger was reached`, `number of times updates trigger was reached` and `number of times eviction trigger was reached`. These are running totals, so the rate is what matters. 4. **Measure the cost to your threads.** The deltas of `page evict attempts by application threads` and `application thread time evicting (usecs)` show how much eviction work your operations are doing. 5. **Check the storage.** Dirty eviction writes to it, so look at device utilisation and latency at the same timestamps. ## What each pattern means | Pattern | Likely meaning | Next move | |---|---|---| | Dirty or updates at the trigger, storage saturated | writes outrun what storage can drain | slow the load, or improve the storage | | Dirty at the trigger, storage has headroom | eviction workers may be short | consider `wiredTigerEvictionThreadsMax`, watch CPU | | Used near 95%, dirty low | reads are filling the cache faster than clean eviction frees it | look at what is reading, and at capacity | | No trigger counters moving | the stall is elsewhere | leave the cache alone and keep looking | The manual's tuning page lists the same two levels, sustained usage above 95% or dirty data above 20%, among the common causes to investigate when execution tickets and queued operations look wrong, so a change in `queues.execution` is consistent with this picture but does not prove it. ## What the second process actually does It is tempting to say the neighbour "stole cache". The internal cache was fixed at startup, so what shrinks is the **filesystem cache**, the operating system's use of free memory for compressed data blocks. - More internal-cache misses become real disk reads, adding I/O to a device already absorbing dirty writes. - If the neighbour writes to the same device, it directly reduces the rate at which dirty pages can drain. - If memory runs out altogether, the host can begin swapping or the operating system's OOM killer can act, since the default did not allow for a neighbour. ## Remedies, in order 1. **Pace the load.** Fewer concurrent workers or smaller batches let dirty content stay under the trigger. This usually works at once. 2. **Separate the neighbour**, or give it its own device, or reduce `cacheSizeGB` so the plan fits the host. 3. **Improve the storage's write capacity** if the load has to run at this rate. 4. **Add eviction threads** only when storage has headroom. `wiredTigerEvictionThreadsMax` defaults to 4 and can be changed at runtime, but more threads writing to a saturated device add little. **Raising the cache** mostly postpones a sustained write problem. The trigger moves up in bytes and there is more room to absorb a burst, but draining still depends on the storage, and the memory comes out of the filesystem cache or the neighbour. ## A note on the field names The manual's 9.0 sample for `wiredTiger.cache` still shows older names such as `pages evicted by application threads`, while the statistics the 9.0.4 source selects for its `spillWiredTiger` section, which come from the same engine, use the names above. Print the whole subdocument on your own version before writing a dashboard against it.

  • Why does p99 react before the median when WiredTiger's application threads start evicting?
    The pressure is intermittent. Usage crosses a trigger, and operations arriving then pay for eviction, including a write for dirty pages, before they continue. Once usage falls back below the trigger, the next operations proceed normally. So the slow tail grows first, and the median moves only when the cache stays at its trigger most of the time.
  • Should you raise wiredTigerEvictionThreadsMax during this incident?
    Only if the storage has headroom and CPU is available. The parameter defaults to 4 and can be changed at runtime, so it is cheap to try. But dirty eviction ends in a write, and more threads writing to a saturated device add contention rather than throughput. Check the device first, and undo the change if nothing improves.
  • The second process on this host is using 20 GB more than last week. Has mongod's WiredTiger cache shrunk?
    No. The size was fixed at startup and still shows in `maximum bytes configured`. What shrinks is the free memory the operating system uses as filesystem cache, so more internal-cache misses reach the disk. The supported way to change the internal cache is a new value and a restart.

  • The second process has reduced the size of the WiredTiger internal cache.
  • Compute the dirty share as dirty bytes over bytes currently in the cache.
  • Raising cacheSizeGB is the first and permanent fix for a dirty-trigger stall.
  • More eviction threads always help, even when the storage is saturated.
  • A single reading of the application eviction counters shows the current rate.

Assumes MongoDB 9.0.4; the application-eviction field names are read from the source, where the 9.0 manual's sample lags, and they can differ on 8.0, so print the subdocument first.