Difficulty: Advanced
What happens when a client's output buffer fills up in Redis, which clients are most affected, and how do you tune and monitor it?
Redis keeps an output buffer per client for replies that have been generated but not yet sent over the socket. If that buffer exceeds the limit set by client-output-buffer-limit, Redis closes the client's connection to protect server memory. This most often hits Pub/Sub subscribers that cannot keep up and replicas that fall behind during a full sync, and in the replica case it can cause an endless resync loop.
The setting has the form client-output-buffer-limit <class> <hard> <soft> <soft-seconds>:
soft-seconds, the client is disconnected.0 disables a limit.The classes and their defaults:
| Class | Default | Why |
|---|---|---|
normal | 0 0 0 (no limit) | Normal clients request replies and read them, so buffers stay bounded |
replica | 256mb 64mb 60 | Replicas receive the write stream during and after sync |
pubsub | 32mb 8mb 60 | Publishers can push faster than a subscriber reads |
When a client is dropped, the server log shows a line saying it was scheduled to be closed for overcoming output buffer limits.
KEYS *, HGETALL on a giant hash, or LRANGE 0 -1 on a long list can create very large buffers. With the default normal limit of 0, nothing stops this, so it shows up as memory spikes instead.The opposite direction exists too: the query buffer holds incoming, not-yet-parsed commands. Its limit is client-query-buffer-limit (default 1 GB).
CLIENT LIST shows per-client omem (output buffer memory), qbuf (query buffer), tot-mem and flags (P for pubsub, S for replica).INFO clients shows client_recent_max_output_buffer and client_recent_max_input_buffer.INFO replication and the logs reveal repeated full syncs.512mb 256mb 120, sized to cover your write rate times the time a full sync takes. Also raise repl-backlog-size so brief disconnects resume with a partial sync.SCAN, HSCAN and paged LRANGE instead.maxmemory-clients can cap the total memory used by all client connections and evict the biggest clients first.# Current limits for all classes
redis-cli CONFIG GET client-output-buffer-limit
# Give replicas more room during full sync
redis-cli CONFIG SET client-output-buffer-limit 'replica 512mb 256mb 120'
# Pub/Sub subscribers: allow larger bursts
redis-cli CONFIG SET client-output-buffer-limit 'pubsub 64mb 16mb 60'
# Find clients with large output buffers (omem in bytes)
redis-cli CLIENT LIST | awk '{for(i=1;i<=NF;i++) if($i ~ /^(id|addr|flags|omem)=/) printf "%s ", $i; print ""}'
# Recent peaks
redis-cli INFO clients | grep recent_max
CONFIG GET reports the replica class as slave and values in bytes. Here a pubsub client (flags=P) has 7 MB buffered, close to the 8 MB soft limit.
client-output-buffer-limit, Pub/Sub Slow Consumers, Replica Output Buffer, Query Buffer, CLIENT LIST