How Redis Manages Client Output Buffers to Prevent Memory Overload
Redis allocates a dedicated output buffer for each client—whether a regular user, slave, monitor, or Pub/Sub subscriber—and employs size and duration limits to automatically close connections when buffers grow too large, thereby preventing memory exhaustion and potential system crashes.
Redis allocates an output buffer for each client connection, providing a dedicated space for the client’s response data.
The client can be a regular user client, a slave, or a monitor.
After processing a request, Redis copies the response into the client’s output buffer and then proceeds to the next request while the client reads the data over the network.
If the output buffer is not properly controlled, it may consume excessive memory and cause system crashes, for example when a simple command generates a huge reply or when the rate of generated replies exceeds the rate at which they are sent to the client, leading to buffer accumulation.
To prevent this, Redis implements protection mechanisms with size and duration limits that differ by client type.
Two limiting methods are used: (1) a size limit that closes the client connection when its buffer exceeds a threshold, and (2) a time‑based limit that closes the connection when the buffer remains excessively large for a certain period.
Policies per client type are:
Ordinary clients have no limit (size 0) and typically use a blocking request‑response pattern, which rarely causes buffer buildup.
Pub/Sub clients have a size limit of 32 MiB; connections are closed if the buffer exceeds 32 MiB or if it stays above 8 MiB for 60 seconds.
Slave clients have a size limit of 256 MiB; connections are closed if the buffer stays above 64 MiB for 60 seconds.
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.
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.
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.
