Home > Database > Redis > body text

Redis learning talks about the single-threaded reactor model

青灯夜游
Release: 2021-12-09 09:54:53
forward
1867 people have browsed it

This article will talk about the single-threaded reactor model, I/O model, and multi-threaded I/O model in Redis. I hope it will be helpful to you!

Redis learning talks about the single-threaded reactor model

High performance of redis

  • Pure memory access, all data is in memory, and all operations are For memory-level operations, the memory response time is at the nanosecond level. Therefore, the CPU of the redis process basically does not have disk I/O waiting time and memory read and write performance problems. The CPU is not the bottleneck of redis (memory size and network I/O are the bottleneck of redis, that is, the gap between the client and the server. network transmission delay). [Related recommendations: Redis Video Tutorial]
  • adopts a single-thread model, and single-thread implementation is simple. Avoids the overhead caused by frequent context switching of multiple threads and synchronization mechanisms such as locks
  • Simple and efficient basic data structures: dynamic strings (SDS), linked lists, dictionaries, jump linked lists, integer sets and compressed lists. Then redis uses this basis to implement objects that users can operate: strings, lists, hashes, sets, ordered sets and other objects
  • reactor mode network event processor. It uses I/O multiplexing to monitor multiple sockets at the same time, which is an efficient I/O model. For reactor-related knowledge, you can read this articleFramework: See the Linux high-performance network IO Reactor model

Why use single thread

  • Uses a single thread to avoid unnecessary context switching and competition conditions; there is no switching caused by multiple threads that consumes the CPU
  • There is no need to consider various lock issues, and there is no locking and releasing There is no performance consumption due to possible deadlocks in lock operations. It is simple and maintainable. Multi-thread mode will make program writing more complex and troublesome. Single-thread implementation is easy to implement.
Redis is a single-threaded system?

We often say that redis is single-threaded because its network event processing model reactor is single-threaded
  • If a client request deletes millions of key values, then this The command may cause blocking. In redis 4.0, we chose to introduce multi-threading to implement this type of non-blocking commands
  • In the redis6.0 version, multi-threading was officially introduced to process the client's I/O read and write responses, while the processing of redis command events is still in Main thread single-line processing
  • If it is for the entire redis system, there will always be other threads to process asynchronous tasks, such as AOF and RDB synchronization
redis I/O model

redis is fast in processing, not only because it is a single-threaded pure memory system, but also because it adopts the Reactor model and uses I/O multiplexing to process external requests. , Reduce network connection, read and write waiting time. Enable it to handle a large number of client requests concurrently in network I/O operations, achieving high throughput and high concurrency

Redis learning talks about the single-threaded reactor model

redis multi-threading Version I/O Model 6.0

Redis learning talks about the single-threaded reactor modelFor more programming-related knowledge, please visit:

Introduction to Programming

! !

The above is the detailed content of Redis learning talks about the single-threaded reactor model. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:juejin.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!