MongoDB – Commands to Check MongoDB Performance on Linux

0

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:

Mongodb XFS Filetype

Figure 1. Mongodb XFS Filetype

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:

MongoDB THP Status

Figure 2: MongoDB Transparent Huge Pages Status

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 File Access Time Settings

Check File Access Time Settings

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>
Ajitesh Kumar

Ajitesh Kumar

Ajitesh has been recently working in the area of AI and machine learning. Currently, his research area includes Safe & Quality AI. In addition, he is also passionate about various different technologies including programming languages such as Java/JEE, Javascript and technologies such as Blockchain, mobile computing, cloud-native technologies, application security, cloud computing platforms, big data etc.

He has also authored the book, Building Web Apps with Spring 5 and Angular.
Ajitesh Kumar

Leave A Reply

Time limit is exhausted. Please reload the CAPTCHA.