There are some important elements must be considered carefully for tuning database performance.
1. File Systems
- Using XFS as it generally performs better with MongoDB.
- With the WiredTiger storage engine, using XFS is strongly recommended for data bearing nodes to avoid performance issues that may occur when using EXT4 with WiredTiger.
- Set 'noatime' on MongoDB data volumes in /etc/fstab
- “Swappiness” is a Linux kernel setting that influences the behavior of the Virtual Memory manager. The vm.swappiness setting ranges from 0 to 100: the higher the value, the more strongly it prefers swapping memory pages to disk over dropping pages from RAM
- Set vm.swappiness to 1, not 0
- Allocating RAM as much as possible (storage.wiredTiger.engineConfig.cacheSizeGB)
- Transparent Huge Pages (THP) is a Linux memory management system that reduces the overhead of Translation Lookaside Buffer (TLB) lookups on machines with large amounts of memory by using larger memory pages.
- However, database workloads often perform poorly with THP enabled, because they tend to have sparse rather than contiguous memory access patterns. When running MongoDB on Linux, THP should be disabled for best performance
- Avoid overloading the connection resources of a mongod or mongos instance by adjusting the connection pool size to suit your use case.
- Specify connection pool settings in these locations:
- The MongoDB URI
- Your application's MongoClient instance
- Your application framework's configuration files
- Some parameters control connections in /etc/mongod.conf file:
- net.maxIncomingConnections
- setting parameters with setParameter: option
- For improved performance, consider separating your database's data, journal, and logs onto different storage devices, based on your application's access and write pattern.
- Mount the components as separate filesystems and use symbolic links to map each component's path to the device storing it.
- For the WiredTiger storage engine, you can also store the indexes on a different storage device by configuring storage.wiredTiger.engineConfig.directoryForIndexes parameter.