Share
MongoDB Architecture and Internals: Performance Tuning, Server Configuration and Monitoring
A practitioner's guide to MongoDB architecture and internals, drawn from production work on large MongoDB estates. It follows a single request through the driver, mongos, the query layer, the WiredTiger storage engine and disk, and shows where each layer waits and which metric proves it.
What the deck covers: WiredTiger cache, eviction thresholds, journal and checkpoints; the document model and embed vs reference decisions; replica set design, write concern and read concern; sharded cluster architecture and a scoring method for shard keys; MongoDB 7.0, 8.0, 8.2, 8.3 and 9.0 support windows; ESR compound indexes, explain executionStats, aggregation pipeline optimization, schema design patterns and anti-patterns; the Cost-Based Ranker and setQuerySettings; transactions and write conflicts; the Linux host baseline (XFS, transparent hugepages, NUMA, swappiness), mongod.conf, WiredTiger cache sizing, connection pools, the profiler, $queryStats and oplog sizing; and the serverStatus, rs.status and sharding metrics worth alerting on, with thresholds.
Test every change on your own workload before it reaches production, and keep a restore you have timed.
Presented by Shiv Iyer, Founder and CEO of MinervaDB Inc. MinervaDB provides MongoDB consulting, performance engineering, 24x7 consultative support, remote DBA and managed services for self-managed MongoDB and MongoDB Atlas, alongside PostgreSQL, MySQL, MariaDB, SQL Server, ClickHouse, Redis, Valkey and every major cloud DBaaS. More than 900 enterprises rely on us to run the data platforms their businesses depend on.
MongoDB consulting and support: https://minervadb.com/mongodb-consulting/
Talk to us: [email protected] | +1 (844) 588-7287
MongoDB is a trademark of MongoDB, Inc. MinervaDB is an independent, vendor-neutral services company.
Transcript
35 slides
-
MongoDB Performance Engineering Architecture, performance tuning, server configuration and the
metrics that matter Shiv Iyer · Founder and CEO, MinervaDB Inc. linkedin.com/in/thewebscaledba · [email protected] © 2026 MinervaDB Inc. All rights reserved. MinervaDB is a trademark of MinervaDB Inc. MinervaDB -
Agenda 01 Architecture 02 Performance tuning 03 Configuring the server
04 Monitoring metrics Slides 4–12 Request path, WiredTiger, document model, replica sets, sharding, versions Slides 13–23 Method, indexes and ESR, explain, aggregation, schema patterns, planner, transactions Slides 24–29 OS baseline, mongod.conf, cache sizing, connections, profiler, oplog Slides 30–34 What to collect, where it lives, and the thresholds that should page someone © 2026 MinervaDB Inc. All rights reserved. MinervaDB is a trademark of MinervaDB Inc. MinervaDB 2 -
Executive summary MongoDB performance is decided by four things you
control. Fix them in this order; each one hides the next. 1 2 3 4 Model and indexes Cache headroom Configuration Metrics Most slow MongoDB workloads are an accesspattern problem. Design documents from the top query shapes and order compound indexes by Equality, Sort, Range. WiredTiger serves reads from its cache. Keep the hot working set under ~70% of the cache so application threads never have to evict pages themselves. XFS, transparent hugepages off, NUMA interleave, a sized oplog and a deliberate cache setting remove the problems that tuning queries cannot fix. Cache fill and dirty ratio, operation latency, queues, replication lag and oplog window tell you which of the other three is failing. © 2026 MinervaDB Inc. All rights reserved. MinervaDB is a trademark of MinervaDB Inc. MinervaDB 3 -
Architecture Part 1 · How MongoDB serves a request, stores
data and stays available © 2026 MinervaDB Inc. All rights reserved. MinervaDB is a trademark of MinervaDB Inc. MinervaDB -
Every request crosses six layers, and each one has its
own place to wait Path of a single read or write, left to right; the response returns the same way APPLICATION HOST MONGOD PROCESS (PRIMARY) 1 2 3 4 Driver mongos Network Query layer Pool, server selection, retryable writes Routes by shard key; sharded clusters only One thread per connection; auth; admission Parse, plan cache, plan ranking, execute Scatter-gather across all shards Execution tickets; connection storms Plan choice; inmemory sort or spill 5 6 WiredTiger Disk Cache, MVCC, compression Journal and data files Cache eviction; checkpoint stalls fsync latency; IOPS ceiling WHERE IT WAITS A free pooled connection WRITES ONLY: REPLICATION The primary records each write in its oplog as part of step 5. Secondary A Oplog Secondaries pull the oplog and apply it in parallel batches. The driver's acknowledgement waits until the write concern is met: w: 1 after the primary, w: "majority" after 2 of 3 members. Request path © 2026 MinervaDB Inc. All rights reserved. MinervaDB is a trademark of MinervaDB Inc. Background flow pull and apply Secondary B Optional MinervaDB 5 -
WiredTiger serves reads from cache and makes writes durable twice:
journal, then checkpoint DISK WiredTiger cache (uncompressed pages) Application threads Queries, inserts and updates Default: 50% of (RAM − 1 GB), or 256 MB, whichever is larger 3 1 Group commit every 100 ms; replayed after a crash 5 Cache fill 80% Concurrency is per document: two writers wait for each other only when they update the same document. Journal (write-ahead log) 95% Dirty share 5% 20% 4 Below the first mark nothing happens. From it, background threads evict. From the second, your application threads evict too: that is the latency cliff. Data files Consistent snapshot written at each checkpoint: every 60 s or 2 GB of journal 2 OS page cache Holds the same data as compressed blocks, and needs RAM too 1 A thread reads or changes a page in the cache. 2 On a miss, the block is read from disk and decompressed. 3 Every write adds a journal record; j: true waits for its fsync. © 2026 MinervaDB Inc. All rights reserved. MinervaDB is a trademark of MinervaDB Inc. 4 A checkpoint writes dirty pages to the data files in the background. 5 Eviction frees space for new pages, as shown on the gauges. MinervaDB 6 -
Embed or reference is decided per relationship, from how the
data is read EMBED: CHILD INSIDE PARENT { _id: 1042, customerId: 42, status: "paid", lines: [ { sku: "A7", qty: 2 }, { sku: "B3", qty: 1 } ] } One read, one atomic write. The order and its lines come back together and change together. Holds while lines stays bounded: hundreds per order, never unbounded. REFERENCE: CHILD POINTS TO PARENT customers { _id: 42, name: "Acme" } orders { _id: 1042, customerId: 42 } Each side changes on its own. Use when the child grows without limit, is updated often, or is queried across parents. Joined by a second query or $lookup, so keep it off the hot path. Ask six questions per relationship Question Embed if Read with parent in main query? Yes Children bounded in number? Yes, hundreds Child updated alone, often? No Child queried across parents? No Document well under 16 MB? Yes, ~2 MB if hot Atomic with the parent? Yes Four or more "embed" answers: embed. Otherwise reference, from the side that is read more often. Record the choice with a schemaVersion field and a $jsonSchema validator. © 2026 MinervaDB Inc. All rights reserved. MinervaDB is a trademark of MinervaDB Inc. MinervaDB 7 -
Three data-bearing members is the minimum for HA; an arbiter
is not a substitute ZONE A 3 ZONE B Primary Accepts every write; records it in the oplog If zone A fails Application driver 1 2 Secondary Secondary Priority 1; can be elected Priority 1; can be elected oplog, applied in parallel batches heartbeats every 2 s 1 Step order 1 The driver sends the write to the primary. 2 The primary records it; secondaries copy it. 3 With w: "majority" the driver is answered once 2 of 3 members have it. Larger designs: two regions as 3 + 2 members with the DR side at priority 0; three regions as 2-2-1; a hidden member for reporting; a delayed hidden member against human error. © 2026 MinervaDB Inc. All rights reserved. MinervaDB is a trademark of MinervaDB Inc. Zone A stops answering heartbeats. 10 s electionTimeoutMillis passes; a secondary calls an election and wins 2 of 3 votes. Drivers find the new primary; retryable writes are retried once. ZONE C 2 Write and replication 0s Then After Writes the old primary never replicated to a majority are rolled back. Why primary + secondary + arbiter fails An arbiter votes but holds no data. With one data member down, majority writes cannot commit, the primary's cache fills with uncommitted history and latency climbs for every client. MinervaDB 8 -
Write and read concern are a durability contract: set them
per class of data Class of data Write concern Read concern Read preference What you accept Orders, payments, identity { w: "majority", j: true } majority primary Higher write latency; no rollback on failover User-facing content { w: "majority" } local primary Read-your-own-writes on the primary Telemetry, logs { w: 1 } local secondaryPreferred A stated loss window equal to replication lag Reporting n/a majority or snapshot tagged secondary Slightly stale, never rolled-back data Set the cluster default once db.adminCommand({ setDefaultRWConcern: 1, defaultWriteConcern: { w: "majority", wtimeout: 5000 } }) © 2026 MinervaDB Inc. All rights reserved. MinervaDB is a trademark of MinervaDB Inc. • wtimeout on every majority write (5–10 s) makes a lost majority fail fast instead of hanging threads. • w: 1 writes not yet replicated are rolled back into rollback/ files when the primary fails over. MinervaDB 9 -
A sharded cluster adds a routing tier; the shard key
decides whether queries stay targeted TARGETED: SHARD KEY IN THE QUERY SCATTER-GATHER: NO SHARD KEY find({ tenantId: 7, ... }) find({ status: "open" }) mongos routes by shard key Shard 1 Shard 2 Shard 3 replica set P·S·S replica set P·S·S replica set P·S·S Config servers One shard does the work; explain lists a single shard. mongos: stateless router; run several, close to the application. Config servers: a 3-member replica set that holds the chunk map; mongos caches it. Shards: each one is a full replica set with its own primary. © 2026 MinervaDB Inc. All rights reserved. MinervaDB is a trademark of MinervaDB Inc. mongos routes by shard key Shard 1 Shard 2 Shard 3 replica set P·S·S replica set P·S·S replica set P·S·S Config servers Every shard runs it, mongos merges; the slowest shard sets latency. Shard only when one of these holds • Working set exceeds the cache of the largest node you can afford • Sustained writes saturate one primary's disk • A node is too large to restore inside the RTO (~2–4 TB on NVMe) • Data residency needs zone sharding Fix schema and indexes first. Since 8.3 it cannot go back to a replica set. MinervaDB 10 -
Score the shard key before sharding: below 10 of 14
means redesign Criterion Score 2 when Evidence to collect Cardinality Distinct values far exceed shards × 100 $group count of distinct key values Frequency No single value holds more than 1% of documents $sortByCount, top 20 values Monotonicity Not ever-increasing, or hashed to spread it Field type: ObjectId and timestamps are monotonic Query isolation 80%+ of top query shapes include the key or its prefix Access pattern matrix, $queryStats Write distribution Inserts land on many chunks at once Insert pattern by key range Unique constraints Every unique index is prefixed by the key Index register Growth No key value produces jumbo chunks $collStats, document size per key value Default for multi-tenant SaaS: a ranged compound key such as { tenantId: 1, createdAt: 1 }. Hashed _id is the last resort, because it gives up range targeting. © 2026 MinervaDB Inc. All rights reserved. MinervaDB is a trademark of MinervaDB Inc. MinervaDB 11 -
Plan upgrades now: 6.0 and 8.2 are past end of
life, and 7.0 ends in August 2027 MongoDB release support windows, release to end of life Nov 2026 6.0 EOL Jul 2025 7.0 EOL Aug 2027 8.0 to Oct 2029 8.2 EOL Jul 2026 8.3 to Oct 2029 9.0 to Oct 2031 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 8.1 was Atlas-only and ended Sep 2025. Minor releases are stepped in order; 8.0 → 9.0 is the direct major-to-major path. Dates as published by MongoDB, Nov 2026; verify before planning. © 2026 MinervaDB Inc. All rights reserved. MinervaDB is a trademark of MinervaDB Inc. MinervaDB 12 -
Performance tuning Part 2 · Indexes, explain, aggregation, schema patterns
and the planner © 2026 MinervaDB Inc. All rights reserved. MinervaDB is a trademark of MinervaDB Inc. MinervaDB -
Tune by measurement: one hypothesis and one change at a
time 1 2 3 4 5 Capture Locate Hypothesise Verify Top query shapes from $queryStats, the profiler at level 1 and the slow-query log Name the layer that waits: plan, cache, disk, lock, network or replication One cause, stated with the metric that will prove or disprove it Change one thing OUTPUT OUTPUT Access pattern matrix serverStatus, explain, FTDC An index, query, schema or single parameter; secondary or staging first Same workload and window: p99 per shape, keys and docs examined, cache counters OUTPUT OUTPUT OUTPUT Written hypothesis Change record with rollback Before and after numbers Numbers did not move? Undo the change and form the next hypothesis Most work is decided at step 2. Once the waiting layer is named, the fix is usually an index or a schema change, not a server parameter. © 2026 MinervaDB Inc. All rights reserved. MinervaDB is a trademark of MinervaDB Inc. MinervaDB 14 -
Order compound index fields Equality, Sort, Range, so the sort
comes free The query Inside the index: entries are stored in key order customerId status createdAt 41 shipped 2026-03-01 42 new 2026-03-10 42 paid 2026-03-09 42 paid 2026-03-07 42 paid 2026-03-02 42 paid 2026-02-26 What explain then shows 42 paid 2026-02-11 • IXSCAN with no SORT stage • totalKeysExamined ≈ nReturned 42 shipped 2026-03-08 • totalDocsExamined ≈ nReturned, or 0 if the projection is covered 57 new 2026-03-04 db.orders.find({ customerId: 42, status: "paid", createdAt: { $gte: ISODate("2026-02-25") } }).sort({ createdAt: -1 }).limit(20) The index, in ESR order { customerId: 1, status: 1, createdAt: -1 } E Seek straight to customer 42, paid S Already newest first: read in order, no sort R Stop at the first date before 25 Feb Four entries read, four returned. Put the range field before the sort field and the index can no longer return rows in order. © 2026 MinervaDB Inc. All rights reserved. MinervaDB is a trademark of MinervaDB Inc. MinervaDB 15 -
Explain shows whether the index fits the query before you
change anything Capture this with every index recommendation const ex = db.orders.find({ customerId: id, status: "paid" }).sort({ createdAt: -1 }) .limit(20).explain("executionStats"); printjson({ winning: ex.queryPlanner.winningPlan, nReturned: ex.executionStats.nReturned, keys: ex.executionStats.totalKeysExamined, docs: ex.executionStats.totalDocsExamined, ms: ex.executionStats.executionTimeMillis, shape: ex.queryPlanner.planCacheShapeHash }); Read the stage tree bottom-up: IXSCAN → FETCH → SORT / PROJECTION / LIMIT. A COLLSCAN on a large collection is a finding on its own. © 2026 MinervaDB Inc. All rights reserved. MinervaDB is a trademark of MinervaDB Inc. Signal Healthy Investigate when docsExamined ÷ nReturned ≈1 > 10: index does not match the predicate keysExamined ÷ nReturned ≈1 Much greater than 1: range scanned too wide hasSortStage false true: index order misses the sort (ESR) Spill metrics (8.2+) 0 Any spill on a hot path: memory finding shards in explain 1 All shards: scatter-gather, no shard key On 8.3 and later, also read the Cost-Based Ranker fields: a changed plan with unchanged indexes is a planner decision. MinervaDB 16 -
Each index type earns its place for one access pattern,
and costs every write Type Use when Watch for Compound (ESR) Any multi-predicate query shape {a, b} makes a separate {a} redundant Partial Queries always filter a subset, e.g. status: "open" The query must include the filter or the index is ignored Multikey Predicates on array fields One array field per compound index; key count grows with array size TTL Sessions, tokens, logs that expire Deletes run every 60 s on the primary; large expiry waves hit IO Wildcard Unknown or attribute-style field sets Not for the hot path; weak for sorting Hashed Hashed shard keys No range queries on the hashed field Hidden Testing a drop safely Still maintained on every write until dropped Collation Case-insensitive equality and sort Query collation must match the index exactly © 2026 MinervaDB Inc. All rights reserved. MinervaDB is a trademark of MinervaDB Inc. MinervaDB 17 -
Unused indexes cost cache and writes: audit, hide, then drop
Audit Hide Observe Drop Quarterly: $indexStats accesses.ops per index, plus prefix duplicates collMod hidden: true; the planner stops using it, writes still maintain it One full business cycle, including month-end jobs Only after p99 per shape is unchanged; record it in the index register Find candidates and hide one db.orders.aggregate([{ $indexStats: {} }, { $project: { name: 1, ops: "$accesses.ops", since: "$accesses.since" } }]) db.runCommand({ collMod: "orders", index: { name: "status_1", hidden: true } }) Findings to raise on day one • Prefix-redundant indexes: {a} next to {a, b}. • Index set larger than the data on a write-heavy collection (totalIndexSize in $collStats). • Builds during peak: builds are online since 4.4 but still consume IO and cache; run one at a time, off-peak. accesses.ops resets on restart; check since before trusting a zero. © 2026 MinervaDB Inc. All rights reserved. MinervaDB is a trademark of MinervaDB Inc. MinervaDB 18 -
Aggregation pipelines are fast when they shrink the data before
they reshape it $match Uses an index only as the first stage $sort + $limit $project Coalesce into a top-k sort Drop fields early $lookup $group Needs an index on the foreign field Memory grows with distinct keys DOCUMENTS PASSED ON (ILLUSTRATIVE) FILTER AND TRIM FIRST THEN JOIN AND AGGREGATE WHAT IS LEFT Rule Why it matters Put $match and $project as early as possible The optimizer moves $match ahead of $sort, but never through $group, $unwind or $lookup Pair every $sort with $limit Without a limit, a sort holds every document and spills past 100 MB per stage Index the foreign field of every $lookup Otherwise each input document triggers a scan of the foreign collection Bound $facet input with a $match $facet runs every sub-pipeline in memory on the full input Use $merge for incremental views $out replaces the target and takes an exclusive lock at the swap 9.0 adds a per-operation memory cap of max(1 GB, 20% of RAM). Pipelines that spill quietly today may fail with ExceededMemoryLimit after upgrading. © 2026 MinervaDB Inc. All rights reserved. MinervaDB is a trademark of MinervaDB Inc. MinervaDB 19 -
Schema patterns fix performance problems that no index can Subset
Computed Bucket Trigger Trigger Trigger A hot document carries a large, rarely read array The same totals are recalculated on every read Events or readings stored one per document Fix Fix Fix Keep the last N items embedded; full history in a child collection Maintain running totals with $inc on write; reconcile in batch One document per entity per time window, or a native time-series collection Extended reference Outlier Schema versioning Trigger Trigger Trigger Every read joins to fetch two or three fields A few entities blow past the array bound Long-lived collections whose shape changes Fix Flag them with hasOverflow and spill into overflow documents Copy the stable fields into the referencing document, with an update path Fix © 2026 MinervaDB Inc. All rights reserved. MinervaDB is a trademark of MinervaDB Inc. Fix schemaVersion on every document; readers accept N and N−1; migrate lazily MinervaDB 20 -
Six anti-patterns cause most slow MongoDB estates, and each leaves
evidence Anti-pattern Evidence that proves it Fix Unbounded arrays avgObjSize rising with document age; $push in the top shapes; update latency climbing Subset or bucket pattern Thousands of collections and indexes High count of WiredTiger data handles; long checkpoints Consolidate with a discriminator field Case-insensitive $regex COLLSCAN or full IXSCAN for /^x/i queries Collation index, strength 2 $lookup on the hot path $lookup stages among the top query shapes Embed or extended reference Bloated document, one hot field High bytes read per operation for small results Subset pattern, projection No validator on critical data Mixed types for one field across documents $jsonSchema, moderate then strict © 2026 MinervaDB Inc. All rights reserved. MinervaDB is a trademark of MinervaDB Inc. MinervaDB 21 -
From 8.3 the Cost-Based Ranker picks plans; capture plan shapes
before you upgrade What changed • Up to 8.0: the multi-planner races candidate plans for a trial period and caches the winner. • 8.3 and 9.0: the Cost-Based Ranker chooses by estimated cost; the multi-planner remains as a fallback. • Symptom: a query gets slower after upgrade with the same indexes. That is a plan decision, not a missing index. Pin a plan without touching application code (8.0+) db.adminCommand({ setQuerySettings: { find: "orders", filter: { customerId: 1, status: "paid" }, sort: { createdAt: -1 }, $db: "shop" }, settings: { indexHints: { ns: { db: "shop", coll: "orders" }, allowedIndexes: ["customerId_1_status_1_createdAt_-1"] } } }) Upgrade routine 1. Capture winning plan and planCacheShapeHash for the top 50 shapes 2. Upgrade binaries, hold FCV for a burn-in window 3. Compare p99 per shape; pin regressions © 2026 MinervaDB Inc. All rights reserved. MinervaDB is a trademark of MinervaDB Inc. Query Settings replace index filters, which are deprecated. 9.0 adds per-shape maxTimeMS and query knobs. Treat every pin as temporary and review it at the next upgrade. MinervaDB 22 -
Keep transactions short and rare; hot-document contention is a schema
problem 60 s 10,000 <1s default transaction lifetime open transactions allowed in 9.0 our target duration transactionLifetimeLimitSeconds maxConcurrentMultiDocumentTransactions and under 1,000 documents per transaction Why long transactions hurt everyone Signs of hot-document contention • An open transaction pins old versions in the WiredTiger cache, so cache fill and eviction pressure rise for all clients. • WriteConflict retries rising on a few documents, such as a global counter • Use single-document atomicity first; embed what must change together. • 9.0: metrics.operation.writeConflictRetryLimitHit above zero • Let the driver's withTransaction retry TransientTransactionError. © 2026 MinervaDB Inc. All rights reserved. MinervaDB is a trademark of MinervaDB Inc. • Fix with schema (bucketed or sharded counters, computed pattern), not with more retries MinervaDB 23 -
Configuring the server Part 3 · Host baseline, mongod.conf, cache,
connections, profiler and oplog © 2026 MinervaDB Inc. All rights reserved. MinervaDB is a trademark of MinervaDB Inc. MinervaDB -
Fix the host before the database: eight OS settings MongoDB
expects Setting Value Why Check Filesystem XFS, mounted noatime WiredTiger performs best on XFS; atime writes are wasted IO mount | grep xfs Transparent hugepages Disabled THP causes memory bloat and latency stalls /sys/kernel/mm/ transparent_hugepage/enabled Swappiness vm.swappiness = 1 Keep the cache in RAM, avoid swap storms sysctl vm.swappiness NUMA Interleave all nodes Avoids lopsided allocation and remote-memory stalls numactl --hardware Open files and processes ulimit -n ≥ 64000 Every connection and data file uses descriptors ulimit -a for the mongod user Read-ahead 8–32 sectors (random IO) Large read-ahead fills the page cache with unused data blockdev --getra Clock sync chrony or NTP on every member Elections and causal consistency rely on time chronyc tracking Separate volumes Data, logs, backups apart Log and backup IO stop competing with data IO lsblk mongod prints a startup warning for most of these; an empty startupWarnings list is the first pass criterion. © 2026 MinervaDB Inc. All rights reserved. MinervaDB is a trademark of MinervaDB Inc. MinervaDB 25 -
A performance-minded mongod.conf changes a handful of defaults, deliberately storage:
dbPath: /data/db wiredTiger: engineConfig: cacheSizeGB: 28 # see sizing slide collectionConfig: blockCompressor: snappy # zstd for cold data net: bindIp: 10.0.1.15 maxIncomingConnections: 20000 operationProfiling: mode: slowOp slowOpThresholdMs: 100 slowOpSampleRate: 1.0 replication: replSetName: rs0 oplogSizeMB: 51200 setParameter: diagnosticDataCollectionEnabled: true © 2026 MinervaDB Inc. All rights reserved. MinervaDB is a trademark of MinervaDB Inc. Why each block is there • cacheSizeGB: set it explicitly on shared hosts and containers, where the default reads the wrong RAM figure. • blockCompressor: applies to new collections only; choose per collection at create time. • maxIncomingConnections: a ceiling that protects memory when an application pool misbehaves. • slowOp at 100 ms: logs slow operations without the cost of profiling everything. • oplogSizeMB: sized from the oplog window, not left at 5% of disk. • diagnosticDataCollectionEnabled: keeps FTDC on; it is the record you need after an incident. MinervaDB 26 -
The default cache takes half of RAM minus 1 GB;
the rest feeds the OS and connections Default WiredTiger cache by host RAM Sizing targets GB, computed as 0.5 × (RAM − 1 GB) 127.5 GB Hot working set ≤ 70% of the cache Cache ≤ 50% of RAM on a dedicated host Where the other half goes • OS page cache holds compressed data blocks; starving it turns cache misses into disk reads. 63.5 GB • Connections use about 1 MB of stack each; 5,000 connections is 5 GB. • Containers: use cacheSizePct (8.2+) or an explicit cacheSizeGB, sized from the container limit. 31.5 GB 7.5 GB 16 GB 15.5 GB 32 GB 64 GB 128 GB © 2026 MinervaDB Inc. All rights reserved. MinervaDB is a trademark of MinervaDB Inc. 256 GB MinervaDB 27 -
Connections and profiling are both load you add yourself; size
them on purpose Connections Profiler and slow-query log • Size the driver pool per application instance (maxPoolSize), then multiply by instances. That product, not the server limit, is your real connection count. Level Records Use 0 Slow ops to the log only Production default 1 Ops slower than slowms into system.profile Short investigations 2 Every operation Never on a busy primary • Set net.maxIncomingConnections as a safety ceiling. • 8.2+: enable ingress connection rate limiting to survive reconnect storms after a failover. db.setProfilingLevel(1, { slowms: 100, sampleRate: 0.5 }) // current vs available, per member db.serverStatus().connections // { current, available, // totalCreated, active } © 2026 MinervaDB Inc. All rights reserved. MinervaDB is a trademark of MinervaDB Inc. $queryStats (7.0+) aggregates query shapes with far less overhead. In 9.0 it also covers writes, sampled at 1% by default, so read its counts as a sample. MinervaDB 28 -
Size the oplog by time, not disk: at least 72
hours and twice your longest outage 72 h minimum oplog window we accept on production The window must exceed 2 × the longest of: • full backup duration • maintenance window or tolerated secondary outage • initial sync of a new member Default: 5% of free disk, between 990 MB and 50 GB. That is rarely enough on a busy write workload, and a secondary that falls off the end needs a full initial sync. © 2026 MinervaDB Inc. All rights reserved. MinervaDB is a trademark of MinervaDB Inc. Check and resize online rs.printReplicationInfo() // read "log length start to end" in hours db.adminCommand({ replSetResizeOplog: 1, size: 102400, // MB minRetentionHours: 72 }) Replication settings worth reviewing Setting Default Note electionTimeoutMillis 10 s Lower only with measured RTT catchUpTimeoutMillis −1 (unbounded) Bound it in DR designs maxStalenessSeconds not set ≥ 90 s for secondary reads MinervaDB 29 -
Monitoring metrics Part 4 · What to collect, where it
lives and when it should page someone © 2026 MinervaDB Inc. All rights reserved. MinervaDB is a trademark of MinervaDB Inc. MinervaDB -
Four metric families explain almost every MongoDB slowdown Each family
watches one part of the request path from slide 5 Driver mongos Network Query layer 2 1 Cache and storage WiredTiger 3 2 Operations and latency Disk Secondaries 1 3 Queries 4 4 Replication and sharding Is the working set in memory, and is eviction keeping up? How much work arrives, how long it takes, what waits? Which query shapes are slow, and how do they execute? Are copies current, and is data balanced? SOURCE SOURCE SOURCE SOURCE serverStatus().wiredTiger.cache, checkpoint timings Detail: Slide 32 opcounters, opLatencies, queues, connections Detail: Slide 33 Slow-query log, profiler, $queryStats, explain Detail: Slides 16 and 28 rs.status(), oplog window, sh.status(), balancer Detail: Slide 34 Collect continuously, at 10–15 s resolution, and keep the history Self-managed Atlas Always on PMM, or Prometheus with mongodb_exporter and Grafana Atlas metrics API and Performance Advisor, exported to your Prometheus FTDC in diagnostic.data on every member © 2026 MinervaDB Inc. All rights reserved. MinervaDB is a trademark of MinervaDB Inc. MinervaDB 31 -
Cache metrics tell you first when the working set no
longer fits Metric (serverStatus().wiredTiger) What it shows Healthy Alert when cache: bytes currently in the cache ÷ maximum bytes configured Cache fill Steady below 80% Above 95% for 5 min cache: tracked dirty bytes in the cache ÷ maximum Dirty share Below 5% Above 20%: application threads evict cache: pages read into cache (rate) Cache misses Near zero at steady state Sustained rise without a traffic change cache: application threads page write from cache to disk count Foreground eviction Zero or flat Any sustained growth transaction: transaction checkpoint most recent time (msecs) Checkpoint duration Well under 60 s Approaching 60 s concurrentTransactions (7.0+: queues) Ticket use Available tickets remain Queued operations above zero for minutes Thresholds are MinervaDB starting points; tune them to each cluster's baseline. Names follow serverStatus output and can change between versions (9.0 renamed several), so check dashboards after every upgrade. © 2026 MinervaDB Inc. All rights reserved. MinervaDB is a trademark of MinervaDB Inc. MinervaDB 32 -
Latency per operation type matters more than averages across the
server Metric Source What it shows Alert when opLatencies reads / writes / commands serverStatus().opLatencies Average latency per op type (latency ÷ ops) p99 per shape above its SLO opcounters and opcountersRepl serverStatus() Work arriving on the primary and applied on secondaries Sudden step change without a deploy Slow operations Slow-query log, $queryStats Which query shapes are slow, and how often New shape in the top 10 by total time Queued operations serverStatus() queues / globalLock Work waiting for execution tickets or locks Queue above zero for several minutes connections.current ÷ available serverStatus().connections Pool health and connection storms Above 80% of the limit asserts and errors serverStatus().asserts, logs User and server errors Any regular or warning asserts rising Memory limit failures (9.0) metrics.query.operationsFailed DueToMemoryLimit Queries hitting the per-operation cap Above zero © 2026 MinervaDB Inc. All rights reserved. MinervaDB is a trademark of MinervaDB Inc. MinervaDB 33 -
Replication lag and oplog window decide how much you can
lose and how fast you recover Replication Metric Source Alert when Read together Replication lag rs.status() optimeDate gap Above 10 s, or growing 5 min Oplog window rs.printReplicationInfo() Below 72 h Lag tells you the data at risk if the primary fails now. Member state rs.status() stateStr RECOVERING, ROLLBACK or down Elections serverStatus().electionMetrics Any unplanned election Metric Source Alert when Data per shard sh.status(), $collStats Largest > 1.2 × smallest Migrations config.changelog, balancer Failing, or running at peak Metadata checkMetadataConsistency Any inconsistency Sharding © 2026 MinervaDB Inc. All rights reserved. MinervaDB is a trademark of MinervaDB Inc. Oplog window tells you how long a member can be down before it needs a full resync. A secondary whose lag grows while its disks are idle usually points at one hot collection or a large transaction. MinervaDB 34 -
Questions and discussion Test every change on your own workload
first, and keep a restore you have timed. Shiv Iyer · Founder and CEO, MinervaDB Inc. [email protected] · linkedin.com/in/thewebscaledba · minervadb.com © 2026 MinervaDB Inc. All rights reserved. MinervaDB is a trademark of MinervaDB Inc. MinervaDB