Home >Database >Redis >Why redis is single-threaded

Why redis is single-threaded

(*-*)浩
(*-*)浩Original
2019-06-17 13:36:185404browse

So why is Redis single-threaded

Why redis is single-threaded 
We must first understand that Redis is fast! The official FAQ states that because Redis is a memory-based operation, the CPU is not the bottleneck of Redis. The bottleneck of Redis is most likely to be the size of the machine memory or network bandwidth. Since single-threading is easy to implement, and the CPU will not become a bottleneck, it is logical to adopt a single-threaded solution (after all, using multi-threading will cause a lot of trouble!). (Recommended learning: Redis video tutorial)You may cry when you see this! I thought there would be some major technical points that make Redis so fast using a single thread, but I didn't expect an official answer that seemed to fool us! However, we can already clearly explain why Redis is so fast, and precisely because it is already fast in single-threaded mode, there is no need to use multi-threading!

However, our single-threaded approach cannot take advantage of multi-core CPU performance, but we can improve it by opening multiple Redis instances on a single machine!

Warning 1:

The single thread we have been emphasizing here only has one thread to process our network requests. When a formal Redis Server is running, there must be more than one thread. It’s a thread, everyone needs to pay clear attention here! For example, when Redis is persisted, it will be executed as a sub-process or sub-thread (the specific sub-thread or sub-process needs to be studied in depth by the reader);  The "-T" parameter of the ps command indicates the display thread (Show threads, possibly with SPID column.) The "SID" column indicates the thread ID, and the "CMD" column shows the thread name.

Warning 2:

The last paragraph in the official FAQ states that multi-threading will be supported starting from Redis version 4.0. However, multi-threading operations are only performed on certain operations! Therefore, whether this article will still be single-threaded in future versions requires readers to verify! For more Redis-related technical articles, please visit the

Introduction to Using Redis Database Tutorial

column to learn!

The above is the detailed content of Why redis is single-threaded. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn