How fast is Redis? The official answer is that the read and write speed is 100,000/second. If this is a single-threaded situation Will you be surprised by the results of the next run? Why is single-threaded Redis so fast? The reasons are as follows:
Pure memory operation: Redis is completely based on memory. Therefore, the reading and writing efficiency is very high. Of course, Redis has persistence operations. The persistence operations are all fork child processes and use the page cache technology of the Linux system to complete, which will not affect the performance of Redis.
Single-threaded operation: Single-threading is not a bad thing. Single-threading can avoid frequent context switching, which will also affect performance.
Reasonable and efficient data structure
Adopts a non-blocking I/O multiplexing mechanism: multi-channel I/O multiplexing model It is the ability to use select, poll, and epoll to monitor the I/O events of multiple streams at the same time. When it is idle, the current thread will be blocked. When one or more streams have I/O events, it will stop blocking. Wake up in the state, then the program will poll all the streams (epoll only polls those streams that actually emitted events), and only processes the ready streams in sequence. This approach avoids a lot of useless operations.
The above is the detailed content of Why is single-threaded Redis faster?. For more information, please follow other related articles on the PHP Chinese website!