MongoDB requires disabling of transparent_hugepages in Ubuntu 16.04 for performance enhancements. In order to achieve this we need to make a script that is automatically executed when system reboots. Follow the following steps to enable this in your linux installation:

Step 1:
Create a file by name “disable-transparent-hugepages” in /etc/init.d and paste the following lines in it

#!/bin/sh
### BEGIN INIT INFO
# Provides: disable-transparent-hugepages
# Required-Start: $local_fs
# Required-Stop:
# X-Start-Before: mongod mongodb-mms-automation-agent
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Disable Linux transparent huge pages
# Description: Disable Linux transparent huge pages, to improve
# database performance.
### END INIT INFO

case $1 in
start)
if [ -d /sys/kernel/mm/transparent_hugepage ]; then
thp_path=/sys/kernel/mm/transparent_hugepage
elif [ -d /sys/kernel/mm/redhat_transparent_hugepage ]; then
thp_path=/sys/kernel/mm/redhat_transparent_hugepage
else
return 0
fi

echo 'never' > ${thp_path}/enabled
echo 'never' > ${thp_path}/defrag

unset thp_path
;;
esac

Step 2:
Run the following command to enable the service

chmod 755 /etc/init.d/disable-transparent-hugepages
update-rc.d distable-transparent-hugepages defaults
Disabling transparent_hugepages in Ubuntu 16.04

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.