Categories: MongoDBNoSQL

MongoDB – Commands to Check MongoDB Performance on Linux

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:

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:

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

I have been recently working in the area of Data analytics including Data Science and Machine Learning / Deep Learning. I am also passionate about different technologies including programming languages such as Java/JEE, Javascript, Python, R, Julia, etc, and technologies such as Blockchain, mobile computing, cloud-native technologies, application security, cloud computing platforms, big data, etc. I would love to connect with you on Linkedin. Check out my latest book titled as First Principles Thinking: Building winning products using first principles thinking.

Share
Published by
Ajitesh Kumar
Tags: mongodbnosql

Recent Posts

Agentic Reasoning Design Patterns in AI: Examples

In recent years, artificial intelligence (AI) has evolved to include more sophisticated and capable agents,…

1 month ago

LLMs for Adaptive Learning & Personalized Education

Adaptive learning helps in tailoring learning experiences to fit the unique needs of each student.…

1 month ago

Sparse Mixture of Experts (MoE) Models: Examples

With the increasing demand for more powerful machine learning (ML) systems that can handle diverse…

2 months ago

Anxiety Disorder Detection & Machine Learning Techniques

Anxiety is a common mental health condition that affects millions of people around the world.…

2 months ago

Confounder Features & Machine Learning Models: Examples

In machine learning, confounder features or variables can significantly affect the accuracy and validity of…

2 months ago

Credit Card Fraud Detection & Machine Learning

Last updated: 26 Sept, 2024 Credit card fraud detection is a major concern for credit…

2 months ago