Skip to content

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

Key points

  • One thread means one slow command delays all clients.
  • KEYS in production is a classic outage.
  • Big keys make simple commands expensive.
  • Forks for persistence can cause pauses on large instances.

Where latency comes from

Time seen by the client is network plus queueing plus execution. Redis commands are normally microseconds, so a millisecond measurement generally comes from queueing behind something slow, the network, or the host stalling.

Common causes

  • O(N) commands: KEYS, SMEMBERS on huge sets, HGETALL on big hashes.
  • Big keys, including large deletes.
  • Fork for RDB or AOF rewrite on an instance with a lot of memory.
  • Swapping or a noisy VM.
  • Slow disk with appendfsync always.
  • Many keys expiring at the same moment.

Diagnose it

Redis has built-in tools for every one of these.

bash
# 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_ratio

Fixes

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.

Frequently asked questions

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

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.