Configuration Procedure

Limit Change

The number of processes available for MongoDB in the system is not enough, you need to change the default settings by editing the /etc/security/limits.d/20-nproc.conf file and paste the following lines at the end (source: MongoDB website):

Transparent Hugepages Deactivation

To get better performances, it is also recommended to disable transparent hugepages by creating a tuned profile (it is perfectly possible to run MongoDB without the tuned daemon but, in this case, to get good performances will require much more efforts from you) (source: MongoDB website) (if you use an other method, be careful about this bug).

Create the /etc/tuned/no-thp directory:

# mkdir /etc/tuned/no-thp

Create the /etc/tuned/no-thp/tuned.conf file and paste the following lines into:

[main]
include=virtual-guest
[vm]
transparent_hugepages=never

Note1: virtual-guest is supposed to be your current active profile, change it if needed.
Note2: Additional tips are available here.

Access From Outside

Note: By default, the MongoDB service only listens to the local network interface (127.0.0.1). To be able to interact with any other server, comment the BindIP directive in the /etc/mongod.conf configuration file and update the Firewalld configuration with:

IO Scheduler and Read-Ahead Configuration

The deadline IO scheduler should be chosen in all the cases except when dealing with virtual machines where the noop scheduler is the best: it is useless to ask a virtual machine to order its IO when all the work is done at the hypervisor level.

The Read-Ahead setting defines how much data is stored in the cache for each read. This is a way to increase efficiency in case of sequential reads.

As MongoDB reads are not sequential, this ends up wasting cache space.

Percona (see links below) provides a nice way to specify both configurations at the same time.

In the case of a physical server, create the /etc/udev/rules.d/60-sda.rules file and paste the following lines:

Note: You can test the IO scheduler in place with # cat /sys/block/sda/queue/scheduler and the Read-Ahead parameter with # blockdev –getra /dev/sda

Filesystem Configuration

XFS is the best available option when choosing a filesystem, EXT4 being a second-best option.

Also, to avoid access-time metadata updates by default, add the flag noatime to the filesystem mount options in the /etc/fstab file. After a reboot or umount/mount operations with MongoDB stopped, this change will reduce the amount of useless disk IO activity.