Redis client handling

  • See how many sockets share the event loop, command executor and in-memory keyspace.
100%
One Redis server processMany sockets share one command executorClient / applicationDiscovery / coordinationStored datacommandspipelinerepliesdispatchdispatchread / mutatequeue replydrainThis connection submits ordinary commands and drains replies promptly.Client AReads repliesThis connection continues sending a pipeline faster than it consumes the resulting response bytes.Client BSlow receiverRedis tracks socket readiness and per-connection protocol state. It reads incoming bytes, parses complete commands and maintains pending replies.A · connectionQuery / reply buffersUnread requests and pending output belong to this connection. The kernel socket buffers can absorb some traffic before Redis output memory begins growing.B · connectionSocket + query bufferOrdinary commands run on the main execution thread of this Redis 7.2 process. Multiplexing allows many connections to share it. I/O and background tasks can use other threads or processes.Event loopCommand executionCommands address data structures held by this server. CPU time spent processing a large collection can delay unrelated clients on the same process.In-memorykeys and valuesReply bytes accumulate when the sender produces them faster than B and the network drain them. Per-client and aggregate limits can trigger a disconnect.B · pendingreply bytescommandspipelinerepliesdispatchdispatchread / mutatequeue replydrain

Select a component to trace its direct connections. Drag to pan · Ctrl + wheel or pinch to zoom.

  • A and B each have a socket and a request buffer. Their commands take turns on the same main thread and access the same in-memory keys.
  • B sends several commands before reading their replies. If Redis produces 12 MiB/s and B drains 3 MiB/s, pending output can grow by about 9 MiB/s once socket buffers fill.
  • A limit on B’s output can disconnect B. A long-running command on the shared thread can delay both clients.
  • Each connection owns protocol state and buffers. One expensive command can delay other clients sharing the main execution thread.
  • Client B’s pending replies consume process memory. Larger client pools and deeper pipelines increase the number of outstanding bytes.
Redis client handling

Redis client handling

Redis Open Source 7.2 architecture

Socket readiness and command work

  • The server registers nonblocking sockets with its event loop. Each connection holds its own request parser, query buffer and pending output.
  • Complete commands already read from a pipeline can be processed together. Pipelining reduces round trips and can increase the amount of queued reply data.
  • A costly keyspace operation consumes main-thread execution time while other ready clients wait. Optional I/O threads can help move bytes. A blocking list command can park its client and yield execution until data arrives.

A slow receiver under load

  • In this illustrative Redis 7.2 configuration, normal-client output has a 32 MiB hard limit and an 8 MiB soft limit with a 10 s continuous excess.
  • Once transport buffering is full, producing 12 MiB/s against 3 MiB/s drain grows Redis output by about 9 MiB/s. From empty, the hard limit could be reached in roughly 3.6 s, before the soft timer expires.
  • Actual growth depends on reply encoding, socket buffers, batching and allocations. Connection closure can leave the client uncertain which pipelined writes executed.
  • maxmemory-clients bounds aggregate eligible client memory. Count replication buffers and keyspace memory separately when choosing the process budget.
Per-client and aggregate memory budgetsconf
# Redis 7.2 teaching fragment. Values illustrate independent limits.
# Select limits from connection counts, reply size, drain rate and memory.
maxclients 1000
client-output-buffer-limit normal 32mb 8mb 10
maxmemory-clients 64mb

# For a local observation, sample CLIENT LIST and INFO clients.
# Compare clients' qbuf, omem and tot-mem with process memory and latency.

Distinguish two latency incidents

Observation Next comparison Decision
Many clients slow together, little pending output Per-command latency, expensive operations and server CPU Bound work per command or distribute key ownership.
A single connection shows increasing omem Reply production, receiver throughput and transport backlog Reduce pipeline depth/reply size or improve the receiver.
  • Use CLIENT LIST for a bounded view of qbuf, omem and total client memory. INFO clients gives aggregate context. A connected-client count alone predicts neither memory nor latency.