MongoDB 3.x Performance Secrets: Benchmarks, Issues, and Best Practices
This article presents comprehensive MongoDB performance benchmarks, discusses version-specific issues, and offers practical best‑practice recommendations for schema design, driver usage, replication, and monitoring to help engineers optimize their deployments.
This article shares MongoDB performance insights, test results, and practical recommendations based on real‑world experience.
Standalone Test
Benchmark on a 24‑core machine with PCIe SSD using MongoDB 3.0.4, snappy compression, journaling enabled, and write concern w=1.
<code>3.0.4 / snappy / standalone / w=1 / enable journal / 1k per document</code>Results:
<code>[OVERALL], Throughput(ops/sec), 118253.63038645286
[UPSERT], AverageLatency(us), 496.5021718
[UPSERT], 99thPercenTleLatency(ms), 0</code>Replica Set Test
Same hardware, replica set configuration.
<code>3.0.4 / snappy / replicaTon / w=1 / enable journal</code>Results:
<code>[OVERALL], Throughput(ops/sec), 68947.44825494009
[UPSERT], AverageLatency(us), 844.9684893
[UPSERT], 99thPercenTleLatency(ms), 0</code>Read‑Write 95:5 Scenario
<code>3.0.4 / snappy / replicaTon / w=1 / enable journal read:write=95:5</code>Results:
<code>[READ], AverageLatency(us), 394.409190121636
[READ], 99thPercenTleLatency(ms), 0
[UPDATE], AverageLatency(us), 562.6090867394253
[UPDATE], 99thPercenTleLatency(ms), 0</code>Checkpoint/eviction algorithms are still being improved; MongoDB 3.0.6 shows greater stability.
Disk Space Savings
With WiredTiger compression, 1.02 billion documents occupy only 270 GB, about 8 % of the space required by the 2.6 version (3.12 TB for 1.18 billion documents), dramatically reducing SSD/PCIe costs.
Version‑Specific Issues
3.0.2 Issues
Key JIRA issues:
WT‑1941 / SERVER‑18629 – unnecessary fsync of data directory; fixed in 3.0.3. Workaround:
<code>log=(xxx,path=journal/,xxx) // add trailing slash after journal</code>SERVER‑18314 – recommendation to use XFS filesystem.
3.0.4 Issues
Fixed previous issues but introduced memory‑leak problems related to cursor handling.
3.0.6 Issues
Fewer severe problems; many issues were quickly resolved (e.g., WT‑2104).
Driver Issues
An async driver failed to detect primary after failover in replica set tests; thorough testing of new drivers and failover scenarios is essential.
Application Issues
Inconsistent time formats and mixed field types caused query errors. Recommended solutions:
Enforce application‑level schema constraints.
Use tools like variety to detect field type diversity.
Apply table‑level privileges.
Maintain consistent metadata and avoid large documents, overly long field names, and unnecessary indexed arrays.
Connection Issues
Observed half‑open connections from mongos; adjusting keep‑alive settings helped mitigate the problem.
Our Recommendations
Standardize data schema metadata.
Avoid indexed arrays when updates are frequent.
Observe naming restrictions.
Prevent large documents.
Keep field names concise.
Pay attention to TTL timing.
Read MongoDB documentation extensively and stay engaged with the community.
Best Practices – Driver
Set query timeouts (similar to MySQL
statement_timeout) to protect the server from hanging long queries.
Since NoSQL lacks SQL tuning, deep dive into schema and architecture design, and perform code reviews.
Best Practices – Application
Avoid negative predicates (e.g.,
not in,
!=).
Update only necessary fields instead of reading and rewriting whole documents.
Use
explainto understand query plans.
Choose appropriate read preferences based on workload.
When sharding, select a shard key that balances write load while supporting queries.
Limit each MapReduce job to a single core.
Heterogeneous Replication
Combining technologies to replicate MySQL data into MongoDB for high‑throughput use cases, using a custom VDP solution that parses binlogs and writes to MySQL, Kafka, HBase, MongoDB, etc., via a drag‑and‑drop UI.
Another Scenario
For reporting, extract MongoDB data to HDFS and query with Hive/Presto. Include a
lastupdatetimefield to enable incremental extraction and reduce load on MongoDB.
Automation and Monitoring
MongoDB 3.x provides over 300 monitoring metrics; we collect and visualize them with Zabbix, enabling quick issue detection. Deployment automation is handled with Ansible.
Efficient Ops
This public account is maintained by Xiaotianguo and friends, regularly publishing widely-read original technical articles. We focus on operations transformation and accompany you throughout your operations career, growing together happily.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.