Why Is My Redis Slowing Down? 10 Common Causes and How to Fix Them
This article explains why Redis may become slower, covering benchmark testing, high‑complexity commands, big keys, concentrated expirations, memory limits, fork overhead, huge pages, AOF settings, CPU binding, swap usage, memory fragmentation, and lazy‑free mechanisms, and provides practical optimization steps.
Redis Why It Slows Down
Before judging Redis as slow, you need a baseline performance test on the production server. Use ./redis-cli --intrinsic-latency 120 to measure the maximum latency over 60 seconds; values like 119 µs (0.119 ms) indicate normal latency.
To see latency history, run redis-cli -h 127.0.0.1 -p 6379 --latency-history -i 1, which reports min, max and average latency per second.
If the observed latency is more than twice the baseline, consider Redis slow.
Network Impact
Test network limits with iperf -s -p 12345 -i 1 -M on the server side and iperf -c <server_ip> -p 12345 -i 1 -t 10 -w 20K on the client side.
High‑Complexity Commands
Check the slowlog with CONFIG SET slowlog-log-slower-than 5000 and CONFIG SET slowlog-max-len 500. Commands like SORT , SUNION , ZUNIONSTORE (O(N) or higher) or O(N) commands on very large N increase CPU usage and latency.
Big Keys
Detect big keys using redis-cli -h 127.0.0.1 -p 6379 --bigkeys -i 1. Scan frequency should be limited with the -i interval to avoid OPS spikes.
Concentrated Expiration
Mass expirations at the same time cause latency spikes. Redis uses passive expiration (deleting only on access) and active expiration (periodic random sampling of 20 keys every 100 ms). Heavy active expiration can block the main thread.
Memory Limit and Eviction Policies
When maxmemory is reached, Redis evicts keys according to policies such as allkeys-lru , volatile-lru , allkeys-random , volatile-random , allkeys-ttl , noeviction , allkeys-lfu , volatile-lfu . LRU policies are common but still add latency.
Fork Overhead
Background RDB/AOF rewrite creates a child process via fork. Large instances cause long copy‑on‑write pauses. Check INFO for latest_fork_usec to see recent fork time.
Huge Pages
Transparent huge pages allocate memory in 2 MB chunks, increasing copy time during writes. Disable with echo never > /sys/kernel/mm/transparent_hugepage/enabled.
AOF Configuration
Three fsync policies exist: appendfsync always (high safety, high I/O), appendfsync no (low safety, low I/O), and appendfsync everysec (balanced). Even everysec can block when disk I/O is high, especially during AOF rewrite.
CPU Binding
Binding Redis to a single logical core can cause contention with child processes. Bind to multiple cores of the same physical CPU, or use Redis 6.0’s server_cpulist, bio_cpulist, aof_rewrite_cpulist, bgsave_cpulist settings.
Swap Usage
Check swap with ps -aux | grep redis-server and cat /proc/<pid>/smaps | egrep '^(Swap|Size)'. If significant swap is used, increase memory or add more Redis instances.
Memory Fragmentation
Fragmentation ratio = used_memory_rss / used_memory. Values > 1.5 indicate > 50 % fragmentation; consider restarting (Redis <4.0) or enabling activedefrag yes (Redis ≥ 4.0).
Lazy Free
Use UNLINK or FLUSHALL ASYNC for non‑blocking deletions. Configuration options include lazyfree-lazy-eviction, lazyfree-lazy-expire, lazyfree-lazy-server-del, slave-lazy-flush. Monitor lazyfree_pending_objects via INFO memory.
Optimization Checklist
Avoid O(N) commands; keep N ≤ 300.
Randomize expiration times to spread load.
Detect and avoid big keys; use async eviction where possible.
Control memory usage and choose appropriate eviction policy.
Limit fork size (<10 GB) and schedule persistence during low traffic.
Consider disabling huge pages and swap.
Bind Redis to suitable CPU cores or use Redis 6.0 CPU‑affinity settings.
Tune AOF fsync policy and consider disabling fsync during rewrite.
Signed-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.
Efficient Ops
This public account is maintained by Xiaotianguo and friends, regularly publishing widely-read original technical articles. We focus on operations transformation and accompany you throughout your operations career, growing together happily.
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.
