This is a collection of our notes to tweak redis.
There are few redis default config options inside /etc/redis/redis.conf
you can play with.
By default, redis logs message about it’s periodic database saving to disk. These messages can clutter redis logs. So you may change log level to warning and errors only.
loglevel warning
The default log level is notice which makes scanning redis logs tough.
This is a number of clients redis can handle simultaneously. The default limit is 10000.
maxclients 20000
But you may see warnings such as below in your error log:
# You requested maxclients of 10000 requiring at least 10032 max file descriptors.
# Redis 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 low ulimit. If you need higher maxclients increase 'ulimit -n'.
Please try increasing open file limit first.
If you see warning like above, even after you restart redis, then try following:
/lib/systemd/system/redis-server.service
[Service]
section and add a line LimitNOFILE=64000
in it.systemctl daemon-reload
service redis-server restart
Now redis log must not complain about ulimit. If it does, please open a support request in our forum.
This value is critical if you have very high number of redis connections.
tcp-backlog 8192
Changing above also requires tweaking somaxconn
and tcp_max_syn_backlog
OS parameters.
echo "net.core.somaxconn=65536" >> /etc/sysctl.conf
echo "net.ipv4.tcp_max_syn_backlog=8192" >> /etc/sysctl.conf
sysctl -p
For a warning like below:
# 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.
As described in warning, please run following command.
echo never > /sys/kernel/mm/transparent_hugepage/enabled
Also, add above line to the file /etc/rc.local
for change to persist after a reboot. You do NOT need a reboot now.
For a warning like below:
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.
Run following commands:
echo "vm.overcommit_memory=1" >> /etc/sysctl.conf
sysctl -p