MongoDB WiredTiger Cache Pressure: Working Set Does Not Fit in RAM
Reads cache fill, dirty ratio and eviction pressure; finds index and query issues that inflate the working set. Guides decisions on cache size, index cleanup and hardware.
Operational Safety & Risk Notice
This runbook contains operational intervention steps; several are write-impacting (KILL, terminate, DROP, RESIZE). Verify in a staging environment first, and apply sequentially in production with verification.
1. Symptom & Signals
- Cache kullanımı sürekli maksimuma yakın (M52 > %95), dirty oranı yüksek (M53 > %5, kritik %20).
- Disk okuma (`pages read into cache`) ve yazma gecikmesi artmış; sorgu süreleri uzamış.
- Aralıklı gecikme sıçramaları ("stall"), uygulama thread'lerinin eviction'a katılması.
2. Business & Technical Impact
Sorgu ve yazma gecikmesi artar. Dirty oranı %20'yi aşınca **uygulama thread'leri eviction yapmak zorunda kalır** ve gecikme dramatik artar. Ciddi durumda zaman aşımları ve düşük verim.
3. Diagnosis & Root-Cause Analysis
const w = db.serverStatus().wiredTiger.cache;
({ max_gb: +(w['maximum bytes configured']/1073741824).toFixed(1),
used_gb: +(w['bytes currently in the cache']/1073741824).toFixed(1),
dirty_gb: +(w['tracked dirty bytes in the cache']/1073741824).toFixed(2),
pages_read: w['pages read into cache'],
app_thread_evict: w['application threads page read from disk to cache time (usecs)'] });db.getCollectionInfos({type:"collection"}).map(c => { const s=db.getCollection(c.name).stats(); return { c:c.name, data_gb:+(s.size/1e9).toFixed(2), idx_gb:+(s.totalIndexSize/1e9).toFixed(2) }; })
.sort((a,b)=>b.idx_gb-a.idx_gb).slice(0,10);4. Remediation & Action Plan
db.koleksiyon.hideIndex("indeks_adi"); // sorunsuzsa sonra dropIndexdb.adminCommand({ setParameter: 1, wiredTigerEngineRuntimeConfig: "cache_size=24G" });Yalnızca fiziksel RAM yeterliyse (OS ve filesystem cache için pay bırakın, genelde RAM'in %60'ını aşmayın). Aşırı büyütmek OOM kill'e yol açar.
5. **Kalıcı çözüm:** RAM artırın veya veriyi **shard**'layın; arşiv verisini ayrı koleksiyon/kümeye taşıyın; doküman şemasını sadeleştirin, gereksiz büyük alanları ayırın, TTL ile eski veriyi temizleyin.
5. Verification & Health Checks
- Cache doluluğu stabil (<%80-90), dirty oranı %5 civarında veya altında (M52, M53 normal).
- `pages read into cache` hızı belirgin düştü, sorgu gecikmeleri iyileşti.
- Uygulama thread eviction'ı (`application threads` metrikleri) görünmüyor.
6. Rollback & Contingency Plan
- `setParameter` ile cache boyutu eski değerine alınabilir (kalıcı olması için `mongod.conf` içinde `storage.wiredTiger.engineConfig.cacheSizeGB` kullanın).
- Gizlenen indeks `unhideIndex` ile hemen geri açılır; silinen indeksin yeniden oluşturulması uzun sürebilir.