Troubleshooting guide
Redis latency spikes: how to diagnose and fix them
Redis executes commands one at a time on a single thread. One slow command makes everything behind it wait.
3 min read11 sectionsUpdated
On this page
# Slowest recent commands
redis-cli SLOWLOG GET 10
# Live latency measured from this client
redis-cli --latency -i 1
# Intrinsic latency of the host (run on the server)
redis-cli --intrinsic-latency 30
# Biggest keys (scans safely)
redis-cli --bigkeys
# Fork time and memory fragmentation
redis-cli INFO stats | grep latest_fork_usec
redis-cli INFO memory | grep mem_fragmentation_ratioFixes
Replace KEYS with SCAN. Split big keys and delete them using UNLINK, which reclaims memory in the background. Add random jitter to expiry times. Consider disabling Transparent Huge Pages, which makes forks much costlier. Use appendfsync everysec. Keep clients in the same zone as Redis, and use pipelining when sending many commands.
Is it Redis, or the path to it?
Run --latency from the application host and also on the Redis server itself. If it is fast on the server and slow from the application, look at the network or the client. If both are slow, look at Redis. If --intrinsic-latency reports large values, the host is stalling and Redis is not at fault at all: a virtualised host with noisy neighbours commonly shows this. A client's own event loop can also add latency, so a Node.js process with a blocked event loop will report slow Redis calls even though Redis was fast.
Catch it automatically
Track p99 command latency and slowlog growth with Redis monitoring. Traces in APM show cache time per request. Alert on latest_fork_usec if you use persistence on a large instance.
Is KEYS really that bad?
Yes on large datasets, because it blocks the single thread until it finishes. Use SCAN.
What latency is normal?
Sub-millisecond within one zone is typical.
Does Redis 6 multithreading fix this?
It offloads network I/O only. Commands still execute one at a time.
Check it now, free
- Response time checker: Measure TTFB with DNS, connect, TLS and server time.
Related reading
- MongoDB slow queries: how to find and fix them: Find and fix slow MongoDB queries: use the profiler and explain, spot COLLSCAN and in-memory sorts, and follow the ESR rule when designing compound indexes.
- Why is my website slow? A step-by-step diagnosis: Diagnose a slow website in order: server, loading, stability and responsiveness. Use real-user data, lab tests and traces to find what to fix first.
- Goroutine leaks in Go: how to find and fix them: Find and fix goroutine leaks in Go: read pprof goroutine profiles, spot blocked channels and missing context cancellation, and use goleak in your tests.
- php-fpm "server reached pm.max_children": how to fix it: Fix php-fpm server reached pm.max_children: calculate the right worker count from memory, find slow scripts with the slow log and choose between pm modes.
- Redis connection refused: how to fix it: Fix Redis connection refused on port 6379: server stopped, bind address, protected mode and Docker networking, with redis-cli and ss commands for each cause.
- Redis "max number of clients reached": how to fix it: Fix Redis ERR max number of clients reached: find leaking applications with CLIENT LIST, tune maxclients and file limits, and pool or multiplex connections.
Watch your own site and services with VitalRix
Uptime checks, APM, logs, real-user monitoring, alerts and status pages in one place. Every product has a free tier and no credit card is needed.