Is Redis Single‑Threaded? Uncover Its Core Architecture and Multi‑Threading Features
Redis primarily operates with a single thread using I/O multiplexing (select, poll, epoll) to handle massive concurrent connections, while newer versions introduce optional multi‑threaded networking and use child processes for persistence, maintaining its core single‑threaded design for data processing.
Redis is often asked whether it is single‑threaded or multi‑threaded, single‑process or not; this article provides a comprehensive explanation.
Redis uses a dedicated thread to handle the majority of tasks, including data read/write, but recent versions also include multi‑threaded capabilities for certain operations.
Single‑threaded core
Redis’s single‑threaded data processing is efficient because it leverages I/O multiplexing, allowing one thread to monitor multiple I/O channels such as network connections and file descriptors, thus handling many client requests concurrently.
I/O multiplexing mechanisms
Redis relies on operating‑system system calls like select, poll, and epoll to listen to multiple client sockets.
select – the earliest mechanism, monitors a fixed set of descriptors but degrades with many descriptors.
poll – similar to select but uses a list, supporting more descriptors.
epoll – Linux’s event‑driven mechanism, avoids traversing all descriptors on each call, offering superior performance for high‑concurrency scenarios; Redis prefers epoll on Linux.
Because most Redis operations are in‑memory, combining them with I/O multiplexing minimizes I/O wait and yields high‑performance data handling.
Redis does employ multiple threads in special cases, such as persistence (RDB, AOF) where a child process handles disk writes, and since Redis 6.0 it adds optional multi‑threaded networking for read/write of network requests, while data processing remains single‑threaded.
Illustration of the architecture:
Persistence workflow example:
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.
Mike Chen's Internet Architecture
Over ten years of BAT architecture experience, shared generously!
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.
