redis-benchmark usage and interpreting results, OS-level tuning (transparent huge pages, TCP backlog, ulimit), slowlog analysis, latency percentile monitoring, and the 5 configuration changes that meaningfully improve throughput.
A-14 — Performance Benchmarking and Production Tuning
Who this module is for: Redis is slower than expected — commands are taking longer than they should, throughput is lower than the hardware should support, or latency spikes are occurring under load. This module covers redis-benchmark for baseline measurement, OS-level tuning that meaningfully impacts Redis performance, and the configuration changes that consistently improve throughput in production.
redis-benchmark: Establishing Baselines
redis-benchmark is the official Redis performance testing tool. Always benchmark before tuning — you need a baseline to know whether a change improved anything.
# Basic benchmark: GET and SET throughput with 50 concurrent clients, 100K requests
redis-benchmark -h 127.0.0.1 -p 6379 -c 50 -n 100000
# Benchmark specific commands
redis-benchmark -h 127.0.0.1 -p 6379 -c 50 -n 100000 -t get,set,hset,lpush
# With authentication
redis-benchmark -h 127.0.0.1 -p 6379 -a password -c 50 -n 100000 -t get,set
# Test with different payload sizes (to understand memory bandwidth limits)
redis-benchmark -h 127.0.0.1 -p 6379 -n 100000 -d 1024 # 1KB values
redis-benchmark -h 127.0.0.1 -p 6379 -n 100000 -d 100000 # 100KB values
# Pipeline test (simulate batch operations)
redis-benchmark -h 127.0.0.1 -p 6379 -n 100000 -P 16 # 16 commands per pipeline
# Output in CSV format for analysis
redis-benchmark -h 127.0.0.1 -p 6379 -n 100000 --csv
Interpreting Results
====== SET ======
100000 requests completed in 0.85 seconds
50 parallel clients
3 bytes payload
keep alive: 1
99.68% <= 1 milliseconds
99.91% <= 2 milliseconds
100.00% <= 3 milliseconds
117647.06 requests per second ← throughput
What these numbers mean:
- 117K ops/sec for SET with 50 clients and 3-byte payload is typical for a local Redis
- With 1KB payload: expect 50–80K ops/sec (memory bandwidth becomes the bottleneck)
- With 100KB payload: expect 5–10K ops/sec (dominated by serialisation and network bandwidth)
What redis-benchmark does not test:
- Your actual command mix (most workloads are not 100% GET or 100% SET)
- Real client libraries (ioredis has overhead compared to the raw C client benchmark uses)
- Production network topology (benchmark runs locally by default)
Always supplement with production metrics from INFO commandstats to understand your real-world baseline.
OS-Level Tuning
Redis performance is heavily influenced by OS configuration. These are the settings that matter most.
1. Disable Transparent Huge Pages (THP)
THP causes Redis latency spikes during BGSAVE because copy-on-write must duplicate 2MB pages instead of 4KB pages. Redis explicitly warns you if THP is enabled:
WARNING you have Transparent Huge Pages (THP) support enabled in your kernel.
This will create latency and memory usage issues with Redis.
Disable permanently:
# Disable immediately
echo never > /sys/kernel/mm/transparent_hugepage/enabled
# Persist across reboots (add to /etc/rc.local or systemd unit)
echo 'never' > /sys/kernel/mm/transparent_hugepage/enabled
echo 'never' > /sys/kernel/mm/transparent_hugepage/defrag
Impact: Eliminates latency spikes of 10–100ms that occur during BGSAVE on write-heavy instances.
2. Increase System File Descriptor Limit
Each Redis client connection uses a file descriptor. The default limit (1024 on many Linux systems) is too low for production Redis:
# Check current limits
ulimit -n
# Increase for the Redis process (add to /etc/security/limits.conf):
redis soft nofile 65536
redis hard nofile 65536
# Or set in the Redis systemd service:
[Service]
LimitNOFILE=65536
Also configure in redis.conf:
maxclients 10000 → Redis will set the OS fd limit accordingly
3. TCP Backlog
The TCP backlog queue holds pending connection requests. Under high connection rates, a small backlog causes connections to be silently dropped:
# Increase OS TCP backlog
sysctl -w net.core.somaxconn=65535
sysctl -w net.ipv4.tcp_max_syn_backlog=65535
# Persist in /etc/sysctl.conf
net.core.somaxconn = 65535
net.ipv4.tcp_max_syn_backlog = 65535
Redis also warns when the OS TCP backlog is smaller than its configured backlog:
WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
# redis.conf
tcp-backlog 511
4. Disable Swap (or Configure Swappiness)
Redis accesses data randomly across its entire working set. If any Redis data is swapped to disk, access times jump from microseconds to milliseconds.
# Check if swap is in use
free -h
cat /proc/meminfo | grep Swap
# Disable swappiness (Redis-specific machines):
sysctl -w vm.swappiness=0
# Or reduce swappiness (shared machines):
sysctl -w vm.swappiness=1
Sign in to keep reading
The rest of this module is free — sign in with Google to unlock it and track your progress.
Sign in & RegisterDiscussion
0Join the discussion