Databases 34 min read

Why Is Redis Slowing Down? 11 Common Causes and How to Fix Them

This article explains the typical reasons why a Redis instance becomes slow—such as high latency, expensive commands, big keys, concentrated expirations, memory limits, fork overhead, huge pages, AOF settings, CPU binding, swap usage, and memory fragmentation—and provides concrete diagnostics and optimization steps to resolve each issue.

Java High-Performance Architecture
Java High-Performance Architecture
Java High-Performance Architecture
Why Is Redis Slowing Down? 11 Common Causes and How to Fix Them

1. Why Redis Becomes Slow

Establish a baseline performance for your Redis instance; latency that exceeds this baseline indicates a slowdown.

Run an intrinsic latency test directly on the Redis server to measure the maximum response latency within 60 seconds.

./redis-cli --intrinsic-latency 120
Max latency so far: 119 microseconds

Use --latency-history to view min, max, and average latency over a period.

$ redis-cli -h 127.0.0.1 -p 6379 --latency-history -i 1
min:0 max:1 avg:0.13 (100 samples) ...

2. High‑Complexity Commands

Check the slowlog and avoid commands whose time complexity is O(N) or higher (e.g., SORT, SUNION, ZUNIONSTORE). Set the slowlog threshold and length:

CONFIG SET slowlog-log-slower-than 5000   # 5 ms
CONFIG SET slowlog-max-len 500

3. Big Keys

Identify oversized keys that can cause latency spikes.

redis-cli -h 127.0.0.1 -p 6379 --bigkeys -i 1

4. Concentrated Expiration

Randomize expiration times to avoid many keys expiring simultaneously, or enable lazyfree-lazy-expire (Redis 4.0+) to free memory asynchronously.

# Randomize expiration within 5 minutes
redis.expireat(key, expire_time + random(300))
# Enable lazy expiration
lazyfree-lazy-expire yes

5. Memory Limit Reached

Set maxmemory and choose an eviction policy. Common policies are allkeys-lru and volatile-lru.

allkeys-lru – evict least‑recently‑used keys regardless of TTL.

volatile-lru – evict least‑recently‑used keys that have an expiration.

allkeys-random, volatile-random, allkeys-ttl, noeviction, allkeys-lfu, volatile-lfu

6. Fork Overhead

During RDB snapshots or AOF rewrites Redis forks a child process; the fork time grows with instance size. Monitor latest_fork_usec via INFO:

# latest_fork_usec:59477

7. Transparent Huge Pages (THP)

THP enlarges memory allocation units to 2 MiB, increasing copy‑on‑write cost. Disable it to avoid extra latency.

# Check status
cat /sys/kernel/mm/transparent_hugepage/enabled   # [always] madvise never
# Disable
echo never > /sys/kernel/mm/transparent_hugepage/enabled

8. AOF Configuration

Select an appropriate appendfsync policy. appendfsync everysec balances performance and durability, but during AOF rewrite you may set no-appendfsync-on-rewrite yes to prevent disk‑IO contention.

9. CPU Binding

Bind the Redis process and its background threads to specific CPU cores to reduce context‑switch overhead. Example for Redis 6.0:

server_cpulist 0-7:2          # main thread & IO threads
bio_cpulist 1,3               # background threads
aof_rewrite_cpulist 8-11      # AOF rewrite process
bgsave_cpulist 1,10,11       # RDB snapshot process

10. Swap Usage

Check whether Redis is swapping by inspecting /proc/<pid>/smaps. If swap is used, increase physical memory or add more Redis nodes.

# Example output snippet
Size: 462044 kB
Swap: 462008 kB

11. Memory Fragmentation

Monitor mem_fragmentation_ratio (used_memory_rss / used_memory). If the ratio exceeds 1.5, enable activedefrag with appropriate thresholds.

activedefrag yes
active-defrag-threshold-lower 10
active-defrag-threshold-upper 100

Finally, follow a step‑by‑step troubleshooting checklist: establish baseline latency, eliminate slow queries, randomize expirations, detect big keys, verify AOF settings, ensure sufficient memory, disable THP, tune CPU binding, and monitor swap and fragmentation.

Star icon
Star icon
Redis optimization diagram
Redis optimization diagram
Redis troubleshooting steps diagram
Redis troubleshooting steps diagram
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

optimizationredistroubleshooting
Java High-Performance Architecture
Written by

Java High-Performance Architecture

Sharing Java development articles and resources, including SSM architecture and the Spring ecosystem (Spring Boot, Spring Cloud, MyBatis, Dubbo, Docker), Zookeeper, Redis, architecture design, microservices, message queues, Git, etc.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.