Monitoring, Diagnostics, and Performance Tuning
What this domain covers
Monitoring, Diagnostics, and Performance Tuning tests your ability to read MongoDB metrics, find slow operations, and improve query plans.
Core rules
- mongostat shows operations per second, connections, network, and queue lengths such as qr, qw, ar, and aw. mongotop shows per-collection read and write time.
- db.currentOp() lists in-progress operations; db.killOp() terminates them. The profiler levels are 0 for off, 1 for slowms, and 2 for all. Use level 1 in production.
- explain with executionStats reports keysExamined, docsExamined, nReturned, and stages such as COLLSCAN and IXSCAN. A good plan examines few documents per returned document.
- FTDC collects diagnostic data every 60 seconds in diagnostic.data. Replication lag, cache dirty ratio, tickets, and page faults are key signals.
- WiredTiger has 128 read and write tickets by default; exhaustion shows as queued operations.
Worked example
A query on status and created_at has no index and does a COLLSCAN plus in-memory sort. Create a compound index with status first and created_at second: equality on status, then created_at supports the sort and range. Explain should show IXSCAN, nReturned close to docsExamined, and no SORT stage. If the sort were on a different field, ESR order would change.
Traps
Running profiler level 2 in production; ignoring replication lag; tuning cache size before fixing query plans; and assuming an index helps when the query does not use its prefix.