7 Essential Linux Tweaks to Supercharge Redis Performance
This guide explains seven critical Linux operating‑system settings—memory overcommit, swappiness, Transparent Huge Pages, OOM killer, NTP synchronization, ulimit, and TCP backlog—that together ensure Redis runs reliably and at peak speed.
Redis developers often focus on Redis‑specific configuration, but operating‑system settings are crucial for stable, high‑performance operation.
1. Memory allocation control
vm.overcommit_memory
When vm.overcommit_memory is set to 0, the kernel may reject memory allocation, causing fork failures during background saves. Setting it to 1 allows overcommit and prevents these errors.
# 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.Check the current value: cat /proc/sys/vm/overcommit_memory Set the value:
echo "vm.overcommit_memory=1" >> /etc/sysctl.conf
sysctl vm.overcommit_memory=1Configure a reasonable maxmemory and keep 20‑30% of RAM free.
Centralize AOF rewrite and RDB bgsave management.
Set vm.overcommit_memory=1 to avoid fork failures.
2. Swappiness
Parameter meaning
Swappiness (0‑100) controls how aggressively Linux uses swap. Lower values keep data in RAM; higher values increase swap usage. The default is 60. For Redis, values 0‑1 are recommended on kernels >3.5, otherwise 0.
Configuration
echo {bestvalue} > /proc/sys/vm/swappinessPersist across reboots:
echo vm.swappiness={bestvalue} >> /etc/sysctl.confMonitoring swap
Use free -m to view total swap usage, vmstat 1 for real‑time swap activity, and inspect /proc/<pid>/smaps for per‑process swap consumption.
3. Transparent Huge Pages (THP)
THP can increase latency and memory usage for Redis. Disable it:
echo never > /sys/kernel/mm/transparent_hugepage/enabledPersist the setting by adding the command to /etc/rc.local. On some distributions the path is /sys/kernel/mm/redhat_transparent_hugepage/enabled.
4. OOM killer
Adjust oom_adj for Redis processes to a low value (e.g., -17) to reduce the chance of being killed when memory is scarce.
for redis_pid in $(pgrep -f "redis-server"); do
echo -17 > /proc/${redis_pid}/oom_adj
done5. NTP
Synchronize system clocks to avoid time drift between Redis nodes, which simplifies troubleshooting of Sentinel or Cluster events.
0 * * * * /usr/sbin/ntpdate ntp.xx.com > /dev/null 2>&16. ulimit
Increase the open‑files limit to accommodate maxclients. For example, set ulimit -Sn 10032 or edit /etc/security/limits.conf to raise the soft limit.
7. TCP backlog
Ensure /proc/sys/net/core/somaxconn is at least the Redis tcp-backlog (default 511). If it is lower, Redis will emit a warning.
echo 511 > /proc/sys/net/core/somaxconnSigned-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Programmer DD
A tinkering programmer and author of "Spring Cloud Microservices in Action"
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
