Sysctl optimization updates for Redis, MongoDB, etc.

Sysctl Performance tips for Redis, MongoDB, etc.

# backup:
$ sysctl -a > /home/sysctl_$(date +%Y%m%d).bak
#check:
$ sysctl -a
 
# make changes to sysctl.conf:
$ vi/nano /etc/sysctl.conf
 
# web - nginx, redis, mongo, etc:
vm.swappiness = 10
vm.dirty_ratio = 40
vm.dirty_background_ratio = 10
# for larger servers:
net.ipv4.tcp_rmem = 4096 12582912 33554432
net.ipv4.tcp_wmem = 4096 12582912 33554432
net.core.rmem_max = 33554432
net.core.wmem_max = 33554432
net.ipv4.tcp_window_scaling = 1
net.ipv4.tcp_timestamps = 1
net.ipv4.tcp_sack = 1
#
net.ipv4.tcp_max_syn_backlog = 65536
kernel.keys.root_maxkeys = 1000000
#Raise somaxconn (above 511)
net.core.somaxconn = 4096
 
# vm.overcommit_memory (optional):
# vm.overcommit_memory = 1
####
 
# set in /etc/rc.local (test reboot stickiness)
# ensure changes to sysctl configuration persist across reboots:
$ sysctl -p
 
# disable transparent hugepages (manually):
echo 'never' > /sys/kernel/mm/transparent_hugepage/enabled
echo 'never' > /sys/kernel/mm/transparent_hugepage/defrag
 
# to persist restart (on systemd), create service:
nano /etc/systemd/system/disable-thp.service
    [Unit]
    Description=Disable Transparent Huge Pages (THP)
 
    [Service]
    Type=simple
    ExecStart=/bin/sh -c "echo 'never' > /sys/kernel/mm/transparent_hugepage/enabled && echo 'never' > /sys/kernel/mm/transparent_hugepage/defrag"
 
    [Install]
    WantedBy=multi-user.target
 
# save the file and reload SystemD daemon:
systemctl daemon-reload
 
# start the script and enable it on boot level:
sudo systemctl start disable-thp
sudo systemctl enable disable-thp

more info:

  • https://wiki.mikejung.biz/Sysctl_tweaks
  • https://www.techandme.se/performance-tips-for-redis-cache-server/
  • https://blacksaildivision.com/how-to-disable-transparent-huge-pages-on-centos
  • Leave a Reply