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
Execute following command to check the filesystem:
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.
Following command can be used to check value for no. of processes/threads. The recommended value is 64000.
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
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 &lt;device&gt;
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 &lt;device&gt; &lt;value&gt;
Check TCP KeepAlive Settings
Execute following command to check the TCP keepalive settings
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=&lt;value&gt;
He has also authored the book, Building Web Apps with Spring 5 and Angular.
Latest posts by Ajitesh Kumar (see all)
- Is Blockchain a Database? - July 11, 2018
- Blockchain – Opportunities & Risks for Financial Institutions - July 6, 2018
- MongoDB Commands Cheat Sheet for Beginners - July 6, 2018