This blog represents code samples to check the MongoDB performance settings on Linux. Following configuration settings need to be checked:
- Filesystem as XFS
- Ulimit values
- Transparent huge pages
- Read ahead limit value
- File access time value
- TCP keepalive value
Check Filesystem
MongoDB recommends to use filesystem of type XFS when using WiredTiger as storage engine with MongoDB running on Linux. The details can be found on this page, MongoDB on Linux.
Execute following command to check the filesystem:
blkid
The output would look like following:
Check ulimit values
Check MongoDB recommended values for ulimit for number of open files and number of processes/threads allowed for the user access. The details can be found on this page, Recommended ulimit settings.
Following command can be used to check value for no. of open files. The recommended value is 64000.
ulimit -n
Following command can be used to check value for no. of processes/threads. The recommended value is 64000.
ulimit -u
In addition to above, make sure that value of following is unlimited by executing corresponding commands:
- Command such as ulimit -f for file size
- ulimit -t for cpu size
- ulimit -v for virtual memory
- ulimit -m for memory size
Check Transparent Huge Pages (THP) Setting
MongoDB recommends disabling Transparent hugepages as MongoDB database workloads tend to have sparse rather than contiguous memory access patterns. The details can be found on this page, Disable transparent huge pages (THP).
Execute following command to check the status of THP
cat /sys/kernel/mm/transparent_hugepage/enabled cat /sys/kernel/mm/transparent_hugepage/defrag
The output of above would look like following:
Check File Access Time Setting
Each time the data is read from a file, the filesystems perform an access-time metadata update by default. However, MongoDB (and most applications) does not use this access-time information. This means that access-time updates on MongoDB’s data volume can be disabled. A small amount of disk IO activity that the access-time updates cause, can , thus be avoided.
Use following command to check file access time setting. Note the setting noatime against MongoDb data directory
cat /etc/fstab
The following screenshot represents the output:
Check Read Ahead Limit
For WiredTiger storage engine, MongoDB recommends to set the readahead setting to 0 regardless of storage media type (spinning, SSD, etc.). Setting a higher readahead benefits sequential I/O operations. However, since MongoDB disk access patterns are generally random, setting a higher readahead provides limited benefit or performance degradation. The details on readahead limit for MongoDB can be found on this page, MongoDB production notes.
Following command can be used to get the read ahead limit for MongoDB
sudo blockdev -getra <device>
The output for above command should be 0 if MongoDB storage engine is WiredTiger. One can use command such as following to set the new ireadahead limit value:
sudo blockdev --setra <device> <value>
Check TCP KeepAlive Settings
Execute following command to check the TCP keepalive settings
cat /proc/sys/net/ipv4/tcp_keepalive_time
The recommended value is 120. Read the details here, Does TCP keepalive time affect MongoDB deployments?. To set the keepalive settings to appropriate value, execute the following command:
sudo sysctl -w net.ipv4.tcp_keepalive_time=<value>
- Agentic Reasoning Design Patterns in AI: Examples - October 18, 2024
- LLMs for Adaptive Learning & Personalized Education - October 8, 2024
- Sparse Mixture of Experts (MoE) Models: Examples - October 6, 2024
I found it very helpful. However the differences are not too understandable for me