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

Advantages and disadvantages of using single-process and single-thread model in redis

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

Today, I will talk to you about the advantages and disadvantages of using the single-process single-threaded model in redis. Many people may not know much about it. In order to make you understand better, the editor summarizes the following contents. I hope you can get something according to this article.

Redis adopts KV database of single-process and single-thread model based on memory, which is written by C language. The official data is qps that can reach 1000000 +. This data is no worse than the same memory-based KV database Memcached using single-process multithreading.

The main reasons why Redis is fast are:

Completely based on memory

The data structure is simple, and the data operation is also simple.

Using multi-channel Ipaw O multiplexing model

The first and second points are not discussed in detail, mainly around the third point of the use of multi-channel Icano multiplexing technology to carry out.

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 only processes ready streams sequentially. 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 Redis), and Redis operates data very fast in memory (the operation in memory will not become the performance bottleneck here). The above two points make Redis have high throughput.

Unlike Memcached, Redis does not use Libevent directly, but completes a very lightweight implementation of common interfaces such as select, epoll, evport, and kqueue.

Choose the appropriate interface for different system calls. The default is epoll under linux. Because Libevent is heavier and has a large amount of general code, with a lot of features that Redis does not need, Redis chose to package a set of its own in order to pursue "lightweight" and remove dependence.

Benefits of single process and single thread

The code is clearer and the processing logic is simpler.

There is no need to consider all kinds of locks, there is no lock release lock operation, and there is no performance consumption caused by possible deadlocks.

There is no switching caused by multi-process or multi-thread that consumes CPU performance.

Malpractice of single process and single thread

Multicore CPU performance cannot be achieved, but it can be improved by opening multiple Redis instances on a single machine.

After reading the above, do you have any further understanding of the advantages and disadvantages of using a single-process, single-threaded model for redis? If you want to know more knowledge or related content, 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