Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Why does redis run so fast?

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Why does redis run so fast? Many novices are not very clear about this. In order to help you solve this problem, the following editor will explain it in detail. People with this need can come and learn. I hope you can gain something.

Redis is a pure memory database, which is generally a simple access operation. Threads take up a lot of time, and the time spent is mainly concentrated on IO, so the reading speed is fast.

Again, IO,Redis uses non-blocking IO,IO multiplexing, uses a single thread to poll descriptors, converts database opening, closing, reading and writing into events, and reduces context switching and competition during thread switching.

Redis adopts a single-threaded model, which ensures the atomicity of each operation and reduces the context switching and competition of threads.

In addition, the data structure also helps a lot. Redis uses hash structure throughout the process to read fast, and there are some special data structures that optimize the data storage, such as compressing tables, compressing and storing short data, and skipping tables, using ordered data structures to speed up reading.

In addition, Redis uses its own event separator, which is relatively efficient, uses non-blocking execution mode internally, and has relatively large throughput capacity.

Based entirely on memory, the vast majority of requests are purely memory operations, which is very fast.

The data is stored in memory, and the advantage similar to HashMap,HashMap is that the time complexity of search and operation is O (1).

The data structure is simple and the data operation is simple. The data structure in Redis is specially designed.

The use of single thread avoids unnecessary context switching and competition conditions, and there is no CPU consumption caused by multi-process or multi-thread switching, there is no need to consider all kinds of locks, there is no lock release operation, and there is no performance consumption caused by possible deadlocks.

Non-blocking IO using multi-channel Icano multiplexing model

Using the underlying model is different, the underlying implementation between them and the application protocol for communicating with the client are different. Redis directly builds its own 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 easy to understand. Let's make a simple discussion on the multi-channel Icano reuse model.

(1) Multi-channel Istroke O multiplexing model

The multiplexing model of multiple streams uses the ability of select, poll, and epoll to monitor multiple streams' Icano events at the same time, blocking the current thread when idle, and waking up from the blocked state when one or more streams have Icano events, so the program polls all streams once (epoll polls only those streams that actually emit events) and processes only those that are ready in sequence. This practice avoids a large number of useless operations.

Here, "multiplex" refers to multiple network connections, and "multiplexing" refers to the reuse of the same thread. Using multi-channel IO multiplexing technology allows a single thread to process multiple connection requests efficiently (minimizing the time consumption of network IO), and Redis operates data in memory very fast, that is to say, in-memory operations will not become a bottleneck affecting Redis performance, which mainly makes Redis have high throughput.

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report