Achieving optimal MongoDB performance requires careful tuning of various configuration parameters that affect both read and write operations. This comprehensive guide provides specific parameters, criteria for setting values, and practical examples to maximize your database performance .
Memory Configuration Parameters
WiredTiger Cache Size
The most critical parameter for MongoDB performance is the WiredTiger cache configuration, which determines how much data remains in memory for fast access [1].
Parameter: storage.wiredTiger.engineConfig.cacheSizeGB
Criteria for Setting Value:
- Allocate 50-75% of total system RAM for dedicated MongoDB servers [2]
- For containerized environments, use 50-75% of container memory limit [2]
- Ensure working set (frequently accessed data + indexes) fits in cache [2]
- Monitor cache hit ratio should exceed 90% for optimal performance [3]
Examples:
# For 64GB RAM server - allocate 40GB (62.5%)
storage:
wiredTiger:
engineConfig:
cacheSizeGB: 40
# For 16GB RAM server - allocate 10GB (62.5%)
storage:
wiredTiger:
engineConfig:
cacheSizeGB: 10
# For 8GB container - allocate 5GB (62.5%)
storage:
wiredTiger:
engineConfig:
cacheSizeGB: 5
Monitoring Command:
// Check cache utilization
db.serverStatus().wiredTiger.cache
Key metrics to monitor [2]:
-
maximum bytes configured
: Your configured cache size -
bytes currently in the cache
: Should not exceed maximum -
tracked dirty bytes in the cache
: Should be <5% of cache size -
pages read into cache
: High values indicate cache pressure
Write Performance Parameters
Write Concern Configuration
Write concern controls the acknowledgment level for write operations, directly impacting write speed versus durability [4].
Parameter: Write concern in application connection string or per-operation
Criteria for Setting Value:
- Use
w: 0
for maximum speed with no durability guarantee [4] - Use
w: 1
for balanced performance with primary acknowledgment (default) [4] - Use
w: "majority"
for maximum durability with replica set majority [4]
Examples:
// Maximum speed (no acknowledgment)
db.collection.insertOne({data: "value"}, {writeConcern: {w: 0}})
// Balanced performance (default)
db.collection.insertOne({data: "value"}, {writeConcern: {w: 1}})
// Maximum durability
db.collection.insertOne({data: "value"}, {writeConcern: {w: "majority"}})
Journal Configuration
Journal settings control write-ahead logging for crash recovery [4].
Parameter: storage.journal.enabled
and storage.journal.commitIntervalMs
Criteria for Setting Value:
- Disable journaling (
false
) for temporary/non-critical data to maximize write speed [4] - Increase
commitIntervalMs
from 100ms to 200-300ms for higher throughput [4] - Keep journaling enabled (
true
) for production data requiring durability [4]
Examples:
# Maximum write performance (disable journaling)
storage:
journal:
enabled: false
# Tuned journaling for performance
storage:
journal:
enabled: true
commitIntervalMs: 200
Compression Configuration
Compression affects both storage efficiency and I/O performance [2].
Parameter: storage.wiredTiger.collectionConfig.blockCompressor
Criteria for Setting Value:
- Use
snappy
for write-heavy workloads (faster compression, more disk space) [2] - Use
zstd
for read-heavy workloads (better compression ratio, slower writes) [2] - Use
zlib
for balanced workloads (good compression, moderate CPU usage) [2] - Use
none
for maximum write speed (no compression overhead) [2]
Examples:
# Write-heavy workloads
storage:
wiredTiger:
collectionConfig:
blockCompressor: snappy
# Read-heavy workloads
storage:
wiredTiger:
collectionConfig:
blockCompressor: zstd
# Maximum write speed
storage:
wiredTiger:
collectionConfig:
blockCompressor: none
Network and Connection Parameters
Connection Pool Configuration
Connection pooling reduces connection overhead and improves concurrent access performance .
Parameter: net.maxIncomingConnections
and application-side pool settings
Criteria for Setting Value:
- Set server
maxIncomingConnections
to ~1000 for 16GB RAM systems [2] - Configure application pool size based on concurrent user load [5]
- Use 10-50 connections for typical applications [5]
- Use 100+ connections for high-traffic applications [5]
- Monitor connection wait times and adjust accordingly [5]
Examples:
# Server configuration
net:
maxIncomingConnections: 1000
compression:
compressors: snappy,zstd,zlib
// Node.js application configuration
mongoose.connect('mongodb://localhost:27017/mydb', {
maxPoolSize: 50, // Maximum connections
minPoolSize: 5, // Minimum connections
maxIdleTimeMS: 30000, // Close connections after 30s idle
serverSelectionTimeoutMS: 5000
});
Network Compression
Network compression reduces data transfer overhead, especially beneficial for distributed deployments [2].
Parameter: net.compression.compressors
Criteria for Setting Value:
- Enable compression for cloud deployments to reduce transfer costs [2]
- Use
snappy,zstd,zlib
order for automatic best compression selection [2] - Disable compression for local networks with high bandwidth [2]
Example:
net:
compression:
compressors: snappy,zstd,zlib
Storage Layout Parameters
Directory Organization
Proper directory organization can improve I/O performance by distributing load [2].
Parameter: storage.directoryPerDB
and storage.wiredTiger.engineConfig.directoryForIndexes
Criteria for Setting Value:
- Enable
directoryPerDB: true
for multiple databases with separate storage volumes [2] - Enable
directoryForIndexes: true
for separate index storage volumes [2] - Keep default (
false
) for single volume deployments [2]
Examples:
# Separate storage volumes setup
storage:
directoryPerDB: true
wiredTiger:
engineConfig:
directoryForIndexes: true
# Results in directory structure:
# /data/db/database1/collection/
# /data/db/database1/index/
Operation Profiling Parameters
Performance monitoring parameters help identify bottlenecks [2].
Parameter: operationProfiling.mode
and operationProfiling.slowOpThresholdMs
Criteria for Setting Value:
- Use
mode: 1
to profile operations slower than threshold [2] - Set
slowOpThresholdMs: 100
for identifying slow operations [2] - Use
mode: 2
to profile all operations for detailed analysis [2] - Use
mode: 0
to disable profiling in production for maximum performance [2]
Examples:
# Profile slow operations
operationProfiling:
mode: 1
slowOpThresholdMs: 100
# Profile all operations (debugging)
operationProfiling:
mode: 2
# Disable profiling (production)
operationProfiling:
mode: 0
Complete Performance Configuration Example
Here's a comprehensive configuration example for a high-performance MongoDB deployment on a 64GB RAM server [1]:
# mongod.conf - High Performance Configuration
storage:
dbPath: /data/db
journal:
enabled: true
commitIntervalMs: 200
directoryPerDB: false
wiredTiger:
engineConfig:
cacheSizeGB: 40
directoryForIndexes: false
collectionConfig:
blockCompressor: snappy
indexConfig:
prefixCompression: true
net:
port: 27017
maxIncomingConnections: 2000
compression:
compressors: snappy,zstd,zlib
operationProfiling:
mode: 1
slowOpThresholdMs: 100
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
Monitoring Performance Impact
After implementing these configurations, monitor key performance metrics [1]:
// Cache performance
db.serverStatus().wiredTiger.cache
// Connection statistics
db.serverStatus().connections
// Operation counters
db.serverStatus().opcounters
// Profiling data
db.system.profile.find().limit(5).sort({ts: -1})
The effectiveness of these parameters depends on your specific workload patterns, hardware configuration, and application requirements. Start with conservative settings and gradually tune based on monitoring data to achieve optimal performance for your use case .
Citations:
[1] MongoDB® Tuning Guide for AMD EPYC™ 9005 ... https://www.amd.com/content/dam/amd/en/documents/epyc-technical-docs/tuning-guides/58487_amd-epyc-9005-tg-mongo-db.pdf
[2] 5 Effective Strategies for MongoDB Performance Tuning https://www.percona.com/blog/mongodb-101-5-configuration-options-that-impact-performance-and-how-to-set-them/
[3] MongoDB 101: Tuning WiredTiger Cache After a Memory ... https://www.percona.com/blog/mongodb-101-how-to-tune-your-mongodb-configuration-after-upgrading-to-more-memory/
[4] 🧠 MongoDB Write Optimization: Best Practices & Techniques https://www.linkedin.com/pulse/mongodb-write-optimization-best-practices-techniques-parasuraman-wxtrc
[5] MongoDB Performance Tuning for High-Traffic WebJS Apps https://moldstud.com/articles/p-performance-tuning-mongodb-for-high-traffic-webjs-applications-boost-your-database-efficiency
[6] Performance Tuning - Database Manual - MongoDB Docs https://www.mongodb.com/docs/manual/administration/performance-tuning/
[7] A Performance Cheat Sheet for MongoDB https://severalnines.com/blog/performance-cheat-sheet-mongodb/
[8] MongoDB Tuning Guide https://amperecomputing.com/en/tuning-guides/mongoDB-tuning-guide
[9] 5 Best Practices For Improving MongoDB Performance https://www.mongodb.com/resources/products/capabilities/performance-best-practices
[10] Database Configuration - WiredTiger - MongoDB https://source.wiredtiger.com/develop/database_config.html
[11] Configuration Strings - WiredTiger - MongoDB https://source.wiredtiger.com/10.0.0/config_strings.html
[12] How to optimize my mongodb connection pool when i am ... https://www.mongodb.com/community/forums/t/how-to-optimize-my-mongodb-connection-pool-when-i-am-using-nodejs-in-cluster-mode/282040
[13] Fixing MongoDB Performance Issues: A Detailed Guide https://accuweb.cloud/blog/fixing-mongodb-performance-issues
[14] WiredTiger Storage Engine - Database Manual https://www.mongodb.com/docs/manual/core/wiredtiger/
[15] Optimizing database performance through efficient connection ... https://journalwjarr.com/sites/default/files/fulltext_pdf/WJARR-2025-1111.pdf
[16] MongoDB Performance Tuning: Everything You Need to ... https://stackify.com/mongodb-performance-tuning/
[17] Self-Managed Configuration File Options - Database Manual https://www.mongodb.com/docs/manual/reference/configuration-options/
[18] Connection Pool Overview - Database Manual https://www.mongodb.com/docs/manual/administration/connection-pool-overview/
[19] MongoDB Performance - Database Manual https://www.mongodb.com/docs/manual/administration/analyzing-mongodb-performance/
[20] Tuning Your Connection Pool Settings - Database Manual ... https://www.mongodb.com/docs/v7.0/tutorial/connection-pool-performance-tuning/
[21] Configuring the MongoDB WiredTiger memory cache for ... https://developers.redhat.com/blog/2018/09/17/configuring-the-mongodb-wiredtiger-memory-cache-for-rhmap
Top comments (0)