Understanding Redis 7.0.11 Multithreading: Configuration Options and Execution Flow
This article explains how Redis 7.0.11 implements multithreading, detailing the required configuration flags, the stages where threads are activated or deactivated based on client write‑backlog, and the impact on network I/O and command execution.
Redis 7.0.11 introduces a multithreading mode that can be enabled by configuring two options in the source code: server.io_threads_do_reads and server.io_threads_num . The first flag controls whether reads are performed in threads, while the second sets the number of I/O threads.
In the source, these options are defined with the following calls:
createBoolConfig("io-threads-do-reads", NULL, DEBUG_CONFIG | IMMUTABLE_CONFIG, server.io_threads_do_reads, 0, NULL, NULL), /* Read + parse from threads? */
createIntConfig("io-threads", NULL, DEBUG_CONFIG | IMMUTABLE_CONFIG, 1, 128, server.io_threads_num, 1, INTEGER_CONFIG, NULL, NULL), /* Single threaded by default */During the beforesleep phase, Redis evaluates the write‑backlog of each client; if the backlog exceeds a threshold (typically server.io_threads_num * 2 ), multithreading is activated.
The processTimeEvents stage can also disable the multithreaded mode when the backlog falls below the threshold, ensuring that thread usage adapts dynamically to workload.
When multithreading is active, network reads are performed by a pool of threads, each handling a client’s socket, parsing commands, and then passing the command to the single‑threaded event loop for execution. Responses are written back to the client’s write buffer by the same thread.
Writes to the network follow a similar pattern: a thread from the pool writes the client’s buffered data. If the write cannot finish because of size limits, Redis registers a write event and continues the operation in the next event loop iteration; this continuation is not considered part of the multithreaded mode.
Command execution itself remains single‑threaded, so large keys or values can still block the server, highlighting the need for careful performance considerations when enabling multithreading.
Overall, while Redis’s multithreaded I/O improves network throughput, it is not a complete solution for all performance bottlenecks, especially those related to large payloads and write‑size limits.
Cognitive Technology Team
Cognitive Technology Team regularly delivers the latest IT news, original content, programming tutorials and experience sharing, with daily perks awaiting you.
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.