Home  >  Article  >  Database  >  Why is redis fast?

Why is redis fast?

(*-*)浩
(*-*)浩Original
2019-11-21 13:32:167288browse

Why is redis fast?

1. Completely based on memory, most requests are pure memory operations, very fast. The data is stored in memory, similar to HashMap. The advantage of HashMap is that the time complexity of search and operation is O(1);

2. The data structure is simple and the data operation is also simple. In Redis The data structure is specially designed;

3, uses a single thread to avoid unnecessary context switching and competition conditions, and there is no switching caused by multi-process or multi-threading that consumes the CPU. There is no need to consider various lock issues, there is no locking and releasing lock operations, and there is no performance consumption caused by possible deadlocks;

4,Use multi-channel I/O complex Use model, non-blocking IO;

5, use different underlying models, the underlying implementation methods and the application protocols for communication with the client are different. Redis directly built it itself VM mechanism, because the general system calls system functions, it will waste a certain amount of time to move and request;

The above points are relatively easy to understand, below we focus on multi-channel I/O A brief discussion of the reuse model:

(1) Multi-channel I/O reuse model

The multi-channel I/O reuse model can use select, poll, and epoll. The ability to monitor I/O events of multiple streams at the same time will block the current thread when it is idle. When one or more streams have I/O events, it will wake up from the blocked state, so the program will Polling all streams (epoll only polls those streams that actually emit events), and only processing ready streams in sequence, this approach avoids a lot of useless operations.

Here "multiple" refers to multiple network connections, and "reuse" refers to reusing the same thread. The use of multi-channel I/O multiplexing technology allows a single thread to efficiently handle multiple connection requests (minimizing the time consumption of network IO), and Redis operates data in memory very quickly, which means that operations in memory do not It will become a bottleneck that affects the performance of Redis. The above points mainly contribute to the high throughput of Redis.

The above is the detailed content of Why is redis fast?. 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