Welcome back to How to Know When to Scale Your MongoDB Atlas Cluster. In Part 1, we chose a starting Atlas tier based on what we expected our application to need. Now let’s put that choice to the test. How much traffic can the cluster handle before requests start taking longer than our application can tolerate?
We’ll use a load tester I built with Locust to run the same read-heavy workload against Flex, M10, and M30, increasing the load in stages. At each stage, we’ll measure how much work each cluster completes and whether p95 latency stays below our example target of 200 ms. Then we’ll use Atlas metrics to investigate what happens as response times climb.
The load tester is an unofficial project you can configure to match your application’s mix of reads, writes, and aggregations. If you already have a benchmarking tool, you can use it and follow along with the same approach to measuring performance and interpreting the results.
Understanding the metrics
A benchmark tells us how our MongoDB cluster performs under load, but understanding why performance changes requires looking at the underlying resource metrics.
In MongoDB Atlas, navigate to your cluster's Metrics tab, set the time range to match your benchmark, and select the relevant replica set node. We'll focus on six metrics:
| Metric | What to watch for |
|---|---|
| Operations per second | Throughput plateauing despite increasing demand. |
| Normalized CPU utilization | Sustained high utilization accompanied by rising latency. |
| Operation queues | Operations accumulating as concurrency increases. |
| WiredTiger cache | Increasing eviction pressure or pages being read into cache. |
| Disk IOPS and latency | Growing disk activity accompanied by slower operations. |
| Query targeting | Excessive documents or index keys examined relative to results returned. |
These metrics are most useful when examined together. High CPU utilization isn't necessarily a problem if throughput continues increasing and latency remains acceptable. However, high CPU alongside growing operation queues and deteriorating response times could indicate compute saturation.
Similarly, increased disk activity might suggest that the working set no longer fits comfortably in memory, but it could also result from inefficient queries scanning unnecessary documents.
Before upgrading, investigate whether the workload itself can be improved. Atlas's Query Profiler, Performance Advisor, and MongoDB's explain() command can help identify expensive queries and indexing opportunities.
We'll also measure p95 and p99 latency using our load-testing tool, since averages can hide slow operations that affect application performance. And remember, a throughput plateau doesn't necessarily mean MongoDB is responsible — the application, network, connection pool, or load generator could also be the bottleneck.
Ultimately, we're not looking for a cluster where every metric stays low. We want one that sustains our workload, meets our latency requirements, and maintains sufficient headroom for unexpected demand.
With that in mind, let's put these metrics to work.
Benchmarking your MongoDB workload with Locust
Now that we understand which metrics to monitor, let's see how they behave under increasing load.
For this experiment, I'll use my MongoDB Locust Load Tester to generate a controlled workload against MongoDB Atlas. By gradually increasing the operation rate and comparing application latency with Atlas resource metrics, we can identify where performance begins to deteriorate and investigate whether scaling would help.
The goal isn't to establish a universal queries-per-second limit for a particular cluster tier. It's to demonstrate how to benchmark a MongoDB workload against defined performance requirements.
The scenario: Can our cluster support the expected workload?
Imagine an application currently running on Atlas Free. It's performed well with a small audience, but we're preparing to open it to the public and need to understand whether a dedicated cluster will provide sufficient capacity.
For this experiment, we'll use an M10 cluster and the load tester's read_heavy profile. This simulates primarily indexed lookups and range queries, alongside a smaller proportion of writes and aggregations.
The benchmark uses a 2 GB dataset, although the actively accessed working set may be considerably smaller.
We'll also establish a performance requirement: our application must maintain p95 latency below 200 ms. This is an illustrative application target, not a MongoDB-recommended threshold.
Our objective is to determine how the workload behaves as demand increases, identify where it stops meeting that requirement, and investigate the underlying bottlenecks.
Prerequisites
Before we get started, here's what you'll need:
- Python 3.12 or later, with
pipavailable to install the benchmark dependencies. - A MongoDB Atlas cluster configured for testing. I'll use M10 for this experiment. If you need help creating a cluster, see Get Started with Atlas.
- A MongoDB database user with the permissions required to create and populate the benchmark dataset, and network access configured to allow connections from your load generator.
- MongoDB Atlas Administration API credentials, if you want to collect Atlas resource metrics alongside Locust results. The benchmark can run without them, but database-side analysis will be more limited.
- Docker, Google Cloud CLI (
gcloud), andkubectl, if you want to reproduce the distributed benchmark using Google Kubernetes Engine (GKE). These aren't required for local testing.
Use a dedicated test cluster rather than a deployment serving production traffic. The benchmark creates synthetic data and deliberately increases demand until performance deteriorates.
You can experiment with Atlas Free, but its shared-resource limits make it unsuitable for reproducing the dedicated-cluster results in this tutorial. If testing Free, use the tiny dataset preset (256 MB) rather than small (2 GB), and review the workload safety limits in config/base.yaml.
Setting up the benchmark
Start by cloning the repository and installing its dependencies:
git clone https://github.com/mongodb-developer/mongodb-locust-load-tester.git cd mongodb-locust-load-tester python -m pip install -r requirements.txt Next, copy the example environment configuration:
cp .env.example .env Configure the connection string and any Atlas API credentials required by your environment, then verify that the cluster is defined correctly in tiers.yaml.
This workload is entirely configurable. Feel free to adjust document size, nesting depth, or weights for the different database operations to better represent your workload. Anything you need to change can be found in the /config directory.
The repository includes several workload profiles and dataset sizes, allowing you to adjust the experiment to reflect your application's requirements.
Running a local benchmark
The simplest way to get started is to run Locust locally using benchmarks.orchestrator.
For example:
python -m benchmarks.orchestrator \ --tier M10 \ --profile read_heavy \ --volume small \ --offered-load-stages 10,25,50,75,100,150,200 \ --offered-load-stage-time 60s \ --report This runs a smaller exploratory benchmark, increasing the target operation rate from 10 to 200 operations per second.
The main configuration options are:
| Flag | Purpose |
|---|---|
--tier M10 | Selects the configured Atlas cluster |
--profile read_heavy | Defines the mix of MongoDB operations |
--volume small | Uses the 2 GB dataset preset |
--offered-load-stages | Defines the target operation rates for successive stages |
--offered-load-stage-time 60s | Runs each stage for 60 seconds |
--skip-seed | Reuses an existing dataset |
--report | Generates reports and charts |
Running locally is useful for exploring workload behavior, validating your configuration, and investigating queries.
However, the results presented in this tutorial were not generated on my laptop.
For the full experiment, I increased the offered load to 2,000 operations per second using distributed Locust workers on Google Kubernetes Engine.
Setting up distributed load generation with GKE
As offered load increases, the load generator itself can become a bottleneck. A single process may struggle to maintain the requested operation rate, making it difficult to distinguish database limitations from limitations in the testing environment.
To reduce this risk, I used Google Kubernetes Engine (GKE) with eight Locust worker pods.
To reproduce this setup, you'll need a running GKE cluster, the Google Cloud CLI authenticated to your project, and kubectl configured to access the cluster.
Verify your current Kubernetes context:
kubectl config current-context Your GKE nodes must also be able to pull images from Artifact Registry, and the cluster must have network connectivity to MongoDB Atlas. This includes configuring the Atlas network access list for the load generators' outbound addresses and ensuring the relevant Kubernetes workloads can access the required MongoDB credentials.
We'll package the benchmark application into a container image and push it to Google Artifact Registry.
First, create a Docker repository and configure authentication:
gcloud artifacts repositories create locust-bench \ --repository-format=docker \ --location=<region> gcloud auth configure-docker <region>-docker.pkg.dev Next, build and push the image:
docker build --platform linux/amd64 \ -t <region>-docker.pkg.dev/<project-id>/locust-bench/locust-mongo-bench:latest . docker push <region>-docker.pkg.dev/<project-id>/locust-bench/locust-mongo-bench:latest The --platform linux/amd64 flag ensures the image is compatible with amd64 GKE nodes, which is particularly important when building on an Apple Silicon Mac. If your GKE node pool uses another architecture, build for that architecture instead.
With the image available in Artifact Registry, we can run the distributed benchmark using benchmarks.orchestrator_k8s.
It accepts the same workload configuration as the local orchestrator, with additional options for the container image and number of workers:
python -m benchmarks.orchestrator_k8s \ --image <region>-docker.pkg.dev/<project-id>/locust-bench/locust-mongo-bench:latest \ --tier M10 \ --profile read_heavy \ --volume small \ --workers 8 \ --offered-load-stages 10,25,50,75,100,150,200,300,500,750,1000,1500,2000 \ --offered-load-stage-time 60s \ --report This is the command used to generate the benchmark results presented in this tutorial.
The eight workers distribute load generation across Kubernetes pods, reducing the likelihood that a single process limits throughput. However, distributed load generation doesn't guarantee unlimited capacity. We still need to verify that the workers can sustain the requested operation rate.
If a benchmark fails or terminates unexpectedly, inspect results/<profile>/<volume>/<tier>/k8s_debug.txt. The orchestrator captures Kubernetes job status, pod information, and logs to help diagnose failures.
The 60-second stages are sufficient for an exploratory benchmark, but they aren't a substitute for longer, repeated tests when planning production capacity.
Understanding the results
Benchmark outputs are written to:
results/<profile>/<volume>/<tier>/
The main files are run_metadata.json, locust_stats_history.csv, and atlas_metrics.json, containing execution metadata, Locust performance measurements, and collected Atlas resource metrics.
To summarize the results by load stage, run:
python -m benchmarks.analyze_saturation \ --profile read_heavy \ --volume small \ --tier M10 The analysis distinguishes three throughput measurements:
| Metric | Meaning |
|---|---|
| Offered | The target operation rate requested by the benchmark |
| Started | The rate at which the load generator actually begins operations |
| Achieved | The rate of completed operations, including failures |
We'll examine these alongside p95 latency, error rates, and Atlas resource utilization.
When offered, started, and achieved throughput remain close together, the benchmark is keeping pace with the requested load.
If started throughput falls behind, the generator isn't maintaining the requested rate. This could indicate insufficient load-generator capacity, but slow database operations can also keep simulated users occupied, preventing them from starting additional work.
Similarly, a difference between started and achieved throughput requires investigation into in-flight operations, completion times, and the measurement window before we can identify a bottleneck.
We'll focus primarily on the Atlas primary node because the default MongoDB read preference directs reads to the primary, while writes are also processed there. Averaging utilization across less-active secondary nodes could obscure pressure on the node handling most of our workload.
Two problems that nearly invalidated the benchmark
My initial results were considerably worse than expected. Even at 10 operations per second, some requests were taking more than a minute to complete. Before blaming the cluster, I investigated the workload and the benchmarking tool itself.
The first problem was an expensive aggregation.
Breaking down latency by operation type revealed that AGGREGATE operations were taking between 47 and 270+ seconds.
The query filtered documents by category, so I added an index and inspected the execution plan using explain(). MongoDB switched from a collection scan to an IXSCAN, but the aggregation still took nearly eight seconds because the subsequent $group stage remained expensive.
For this synthetic workload, I changed the aggregation to process a bounded subset of documents, applying $match, $sort, and $limit before $group, supported by a compound index on (category, seq).
This changes the aggregation's semantics, since grouping a limited subset isn't equivalent to grouping all matching documents. It was appropriate for this synthetic workload, but wouldn't be suitable for an application requiring complete aggregation results. The sort also needs a unique ordering to select a deterministic subset.
With these changes, isolated aggregation latency dropped to approximately 280 ms.
The second problem was in the benchmarking tool itself.
Even after fixing the aggregation, achieved throughput consistently matched the previous stage's offered load.
The analyzer was calculating stage boundaries from when Kubernetes received the benchmark job, rather than when Locust actually began generating traffic. Pod scheduling, image pulls, and worker startup introduced a delay of almost an entire load stage.
I corrected the analyzer to infer stage boundaries from observed simulated-user counts, improving measurement alignment. Explicit stage-transition timestamps would be more reliable in future iterations.
Both problems could have led to an unnecessary scaling decision. One came from an inefficient workload; the other from inaccurate measurement. Before deciding that MongoDB needs more resources, make sure you're measuring the workload correctly.
The corrected benchmark results
With those issues addressed, I reran the benchmark against M10.
| Offered ops/s | Started ops/s | Achieved ops/s | p95 latency | Errors | Primary CPU |
|---|---|---|---|---|---|
| 10 | 10.0 | 10.0 | 65.4 ms | 0.0% | 2.0% |
| 25 | 25.0 | 25.0 | 69.6 ms | 0.0% | 2.2% |
| 50 | 49.8 | 49.8 | 64.6 ms | 0.0% | 3.2% |
| 75 | 75.0 | 75.0 | 68.6 ms | 0.0% | 4.4% |
| 100 | 99.6 | 99.6 | 61.4 ms | 0.0% | 5.0% |
| 150 | 149.9 | 149.9 | 65.3 ms | 0.0% | 7.0% |
| 200 | 200.0 | 200.2 | 64.7 ms | 0.0% | 8.7% |
| 300 | 300.0 | 300.2 | 77.5 ms | 0.0% | 12.3% |
| 500 | 498.0 | 498.0 | 103.6 ms | 0.0% | 17.7% |
| 750 | 750.0 | 750.3 | 144.7 ms | 0.0% | 25.9% |
| 1,000 | 1,000.3 | 1,000.1 | 138.9 ms | 0.0% | 33.6% |
| 1,500 | 1,496.3 | 1,501.3 | 449.0 ms | 0.0% | 54.4% |
| 2,000 | 883.2 | 863.9 | 4,240.8 ms | 0.1% | N/A |
CPU values represent the primary node's normalized CPU utilization. No CPU measurement was available for the final stage on this first run.
Up to 1,000 operations per second, the benchmark maintains its requested throughput with no reported errors. More importantly, p95 latency remains below our illustrative 200 ms target, while normalized CPU utilization rises from approximately 2% to 34%.
At 1,500 operations per second, throughput still keeps pace with the offered load, but p95 latency jumps to 449 ms, exceeding our application's performance requirement.
At 2,000 offered operations per second, performance deteriorates sharply. The generator performs only 883 operations per second, achieves approximately 864 completions per second, and has a p95 latency exceeding four seconds.
This demonstrates an important distinction: the point at which throughput breaks down isn't necessarily the point where an application should scale. Our application already breached its latency requirement at 1,500 operations per second, despite maintaining the requested throughput.
These results establish that the tested configuration handled 1,000 operations per second within our latency target during the exploratory benchmark. However, the 60-second stages don't establish long-term capacity, and we haven't tested the range between 1,000 and 1,500 operations per second.
CPU utilization alone doesn't explain the deterioration either. At 1,500 operations per second, normalized CPU reached only 54.4%. To investigate further, we need to examine what was happening inside MongoDB.
Investigating the throughput collapse
To understand the performance deterioration, I examined additional historical metrics from MongoDB Atlas, focusing on operation execution times, disk activity, WiredTiger read tickets, and operation queues.
The most revealing measurements were TICKETS_AVAILABLE_READS and GLOBAL_LOCK_CURRENT_QUEUE_READERS.
WiredTiger uses execution tickets to regulate concurrent operations, while MongoDB's global lock queue metrics track operations waiting for lock acquisition. Although these measure different forms of contention, examining them together helps identify when operations begin accumulating.
For most of the benchmark, approximately 47 read tickets remained available, with no queued readers. As demand increased, available tickets fell sharply.
At the same time, queued readers increased from zero to 14, 14, and eventually 39 across the final three reported minutes.
This provides evidence of substantial concurrency pressure: read execution capacity was exhausted while operations began accumulating in queues.
However, ticket exhaustion doesn't necessarily explain what originally caused operations to slow down. Longer-running operations can occupy execution capacity for longer, creating additional contention.
Other Atlas metrics revealed further evidence of performance degradation:
- Operation execution times: Average read execution time increased substantially, eventually approaching eight seconds.
- Disk performance: Primary read latency increased to approximately 8–10 ms, alongside elevated read IOPS.
- Operation queues: Atlas's total operation queue later peaked at approximately 450.
- WiredTiger cache: Cache fill ratio generally remained around 77–80%, without a sustained increase suggesting cache-fill saturation.
These measurements show that read execution, storage activity, and concurrency pressure all deteriorated during the benchmark. They don't establish a single root cause, but they give us a much clearer picture than CPU utilization or throughput alone.
Importantly, the application had already exceeded its latency requirement at 1,500 operations per second, before the final throughput collapse. That remains our first reason to investigate scaling, regardless of which resource ultimately limited throughput.
What does this mean for scaling?
For our hypothetical application, the benchmark demonstrates that the tested M10 configuration can handle substantial throughput while meeting our latency requirement, but only within the workload and test conditions we've measured.
At 1,500 operations per second, the application no longer meets its latency target. At the final stage, we also observe read-ticket exhaustion and growing read queues alongside a sharp throughput decline.
That gives us a much more useful starting point for deciding what to investigate next.
We could repeat the experiment with smaller load increments between 1,000 and 1,500 operations per second, extend the measurement windows, and compare the results against a larger cluster.
We should also remember that this benchmark represents only one workload profile and dataset. A larger working set could increase cache pressure and disk reads, while additional writes, more complex aggregations, or larger documents could introduce different constraints.
The load tester's balanced and cpu_intensive profiles, along with configurable document sizes, offer a starting point for exploring these scenarios.
We haven't discovered a universal QPS limit for M10. We've demonstrated how to benchmark a particular MongoDB workload, identify where it stops meeting its performance requirements, and use Atlas metrics to investigate why.
Try a larger cluster: Benchmarking doesn't have to be expensive
If your benchmark suggests that your current cluster is approaching its limits, the next step is to test whether a larger tier actually improves performance.
MongoDB Atlas bills dedicated clusters by the hour, prorated for partial hours, so experimenting with a larger tier doesn't require a long-term commitment.
In our M10 benchmark, p95 latency exceeded our 200 ms target at 1,500 operations per second. Rather than assuming an M30 would solve the problem, we could provision a temporary cluster and repeat the experiment, which is exactly what we do below.
For a meaningful comparison, keep the dataset, indexes, workload, offered load, region, and test duration consistent. Allow both clusters to warm up, and ensure the load generator isn't limiting throughput.
Compare throughput, p95/p99 latency, and resource utilization to see whether the larger tier provides a meaningful improvement. If performance barely changes, the bottleneck may lie elsewhere.
Once you're finished, delete the temporary cluster to avoid unnecessary charges.
A few dollars spent benchmarking could prevent a much more expensive scaling decision.
Comparing performance across Atlas tiers
A larger cluster should handle more traffic, but the interesting question is how much more, and what happens when it reaches its limit. We ran the same read-heavy workload against Flex, M10, and M30, ramping traffic from 10 to 2,000 requests per second on each, to see not just how much each could sustain, but where and why it broke down.
Flex hit a hard, early ceiling. It ran cleanly up to 300 requests per second. At 500, it broke: a 4.2 percent error rate and p95 latency over 10 seconds. Beyond that point, extra demand bought almost nothing. Even offered 2,000 requests per second, Flex only processed around 600–640, with errors climbing to 8.7 percent. While this is somewhat above its published ~500 ops/sec limit, the 500-stage figures may include some spillover from adjacent stages, since stage windows are inferred from simulated-user counts. Atlas doesn’t expose process-level metrics for Flex, so we can’t isolate the exact mechanism, only that this is a firm practical ceiling.
M10 looked fine on CPU, right up until it wasn’t. Throughput tracked offered load almost perfectly up to 1,500 requests per second with zero errors, although p95 latency had already reached 449 ms, well past our 200 ms target. Over the same range, primary CPU climbed steadily from about 1.5 to 50.7 percent, a reassuring, proportional curve. At 2,000 requests per second, performance collapsed: achieved throughput fell to 864 req/s, p95 jumped to 4,240 ms, and errors appeared, while CPU barely moved, reaching 54.4 percent. What did change was WiredTiger’s read tickets, which were exhausted as operations queued for the storage engine, alongside slower reads and higher disk read latency. M10 wasn’t obviously short on processing power. The evidence points to concurrency pressure, and CPU alone didn’t reveal it.
M30 never hit a throughput limit in this benchmark. At 2,000 requests per second it was still error-free, with p95 around 215-220 ms (just over our 200 ms target) and CPU at just 21.5 percent, less than half what M10 was using when it failed. That doesn’t mean M30 has no ceiling, only that this workload wasn’t demanding enough to find it.
What the metrics tell us
Throughput says how much work completes; latency says what users actually feel. Flex’s p95 reached 10-13 seconds at its worst once overloaded. M10 stayed under about 150 ms through 1,000 req/s, crossed 200 ms by 1,500, and collapsed at 2,000. M30 never exceeded ~220ms. A cluster can keep completing hundreds of operations a second while delivering latency no user would accept.
At the same offered load, M10 was at 54.4 per cent CPU and already failing; M30 was at 21.5 per cent and fine. CPU tells you computational demand, not whether something else downstream is actually the limiting factor.
The ticket and queue metrics show why: as M10 approached its limit, available read tickets fell and queued readers rose, operations arriving faster than the storage engine could admit them. That’s the kind of bottleneck CPU alone won’t reveal, and why it’s worth watching ticket and queue metrics alongside latency and disk behaviour.
Conclusion
In this benchmark, M10 was still keeping up with the offered load at 1,500 requests per second, but p95 latency had already reached 449 ms. By 2,000 requests per second, throughput had dropped sharply, available WiredTiger read tickets were exhausted, and operations were queuing while primary CPU sat at about 54%. M30 completed the highest load stage without errors, with p95 latency around 215–220 ms, slightly above our target.
For your own application, start with the latency you need at peak traffic and benchmark with a representative mix of queries, data, and indexes. If the cluster misses that target, use Atlas metrics to decide what to investigate. When you’re considering a larger tier, rerun the same test and compare how much headroom it gives you at the latency your application needs.
Now that we have seen how to choose your starting tier, and how to benchmark your application, in Part 3 we will look at how to turn these results into a scaling strategy.














