Why Is Redis Lagging? Key Causes and Practical Fixes
This article explains the main factors that cause Redis latency—including network bottlenecks, Redis’s single‑threaded design, deployment choices, OS settings, and slow commands—and provides concrete commands and best‑practice solutions to diagnose and reduce the delay.
Redis latency is a critical performance indicator that SREs must monitor; high latency can stem from many sources. The article outlines how to locate latency sources and offers practical mitigation steps.
1. Remote Diagnosis
Run the built‑in latency test to bypass network effects:
redis-cli --latency -h 127.0.0.1 -p 63792. Intrinsic Diagnosis
Check Redis’s own latency on the server: redis-cli --intrinsic-latency 50 A latency under 100 µs is considered normal.
3. Factors Causing Latency and Their Solutions
3.1 Network‑Induced Latency
When network throughput reaches the NIC’s processing limit, latency spikes; use 10 GbE multi‑queue NICs.
Excessive client‑server interactions increase latency; reduce unnecessary connections, enable long‑lived connections, and use a connection pool.
3.2 Redis‑Internal Issues
Redis’s single‑threaded, non‑blocking design means any blocking event (e.g., persistence, full sync after a master‑slave offset drift) directly adds latency. Minimize blocking by disabling unnecessary persistence on the master.
3.3 Deployment‑Related Issues
Sentinel or cluster mode often enables persistence (RDB or AOF), which triggers a fork in the main thread. To avoid the fork‑induced pause, enable persistence on replica nodes instead of the master.
3.4 Operating‑System Level
Transparent Huge Pages : Default “always” can cause latency due to extra copy‑on‑write during fork. Consider disabling or setting to “madvise”.
Swapping : Swap introduces I/O blocking. Keep Redis’s resident memory well below total RAM (e.g., < 50 % usage) and disable swap.
NUMA Architecture : NUMA can add latency; use numactl --interleave=all to remove node‑specific constraints.
3.5 Application‑Layer Issues
Slow Commands : Heavy operations such as SORT, LREM, SUNION, and KEYS on large datasets cause delays. Offload expensive reads to replicas or rename keys to avoid costly scans.
Mass Expiration : Large numbers of expiring keys generate latency spikes; set appropriate TTLs and avoid bulk expirations.
By systematically applying the above diagnostics and mitigations, operators can significantly reduce Redis latency in production environments.
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.
ITPUB
Official ITPUB account sharing technical insights, community news, and exciting events.
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.
