Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save shinebayar-g/3145e0c6ace8aabb70cf756924c6463a to your computer and use it in GitHub Desktop.
Save shinebayar-g/3145e0c6ace8aabb70cf756924c6463a to your computer and use it in GitHub Desktop.
Fix redis server startup warnings, redis tuning performance on Ubuntu 16.04
  • Maximum Open Files
You requested maxclients of 10000 requiring at least 10032 max file descriptors.
Server can't set maximum open files to 10032 because of OS error: Operation not permitted.
Current maximum open files is 4096. maxclients has been reduced to 4064 to compensate for maxclients has been reduced to 4064 to compensate for low ulimit. If you need higher maxclients increase 'ulimit -n'.

Solution:

Edit systemd service file sudo vim /etc/systemd/system/redis.service

[Service]
...
User=redis
Group=redis
# should be fine as long as you add it under [Service] block
LimitNOFILE=65536

Then you must daemon reload and restart the service

sudo systemctl daemon-reload

sudo systemctl restart redis.service

To check if it works, try to cat proc limits

cat /proc/PID/limits and you will see

Max open files     65536   65536   files
Max locked memory  65536   65536   bytes

  • Socket Maximum Connection
WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
  • Memory Overcommit
WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.

Solution:

Since these two are related, we will solve it at once.

sudo vim /etc/sysctl.conf

# Add at the bottom of file
vm.overcommit_memory = 1
net.core.somaxconn=1024

Now for these configs to work, you need to reload the config

sudo sysctl -p


  • Transparent Huge Pages
WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.

Solution:

To permanently solve this, follow the log's suggestion, and modify rc.local

sudo vi /etc/rc.local

if test -f /sys/kernel/mm/transparent_hugepage/enabled; then
    echo never > /sys/kernel/mm/transparent_hugepage/enabled
fi

This require you to reboot, backup your data or do anything you need before you actually do it!!

sudo reboot

Now check you redis log again, you should have a redis server without any errors or warnings.

Analytics

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment