In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces a detailed introduction about Redis, which is very detailed and has a certain reference value. Friends who are interested must finish it!
High concurrency and Rapid causes of Redis
1.redis is based on memory, and the read and write speed of memory is very fast
2.redis is single-threaded, saving a lot of time for context switching threads.
3.redis uses multiplexing technology to handle concurrent connections. The internal implementation of non-blocking IO adopts epoll and adopts a simple event framework implemented by epoll+ itself. Read, write, close, and connect in epoll are all converted into events, and then take advantage of the multiplexing feature of epoll to never waste any time on io.
The following focuses on the reasons for the speed of single-threaded design and IO multiplexing core design.
Why Redis is single threaded
1. Official answer
Because Redis is a memory-based operation, CPU is not the bottleneck of Redis, and the bottleneck of Redis is most likely to be the size of machine memory or network bandwidth. Since single-threading is easy to implement and CPU will not be a bottleneck, it makes sense to adopt a single-threaded solution.
two。 Performance index
With regard to the performance of redis, it is also available on the official website, and ordinary laptops can easily handle hundreds of thousands of requests per second.
3. Detailed reasons
1) No performance consumption of various locks is required
The data structures of Redis are not all simple Key-Value, but also complex structures such as list,hash. These structures may perform very fine-grained operations, such as adding an element after a long list and adding or deleting from the hash.
An object. These operations may require a lot of locks, resulting in a significant increase in synchronization overhead.
In short, in the case of a single thread, 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.
2) single-thread multi-process cluster scheme
The power of single thread is actually very powerful, and the efficiency of each core is also very high, so multi-thread can naturally have a higher performance limit than single-thread, but in today's computing environment, even the upper limit of single-machine multi-thread can not meet the needs. What needs to be further explored is the scheme of multi-server clustering, and the technology of multi-thread in these schemes is still useless.
Therefore, single-threaded, multi-process cluster is a fashionable solution.
3) CPU consumption
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.
But what if CPU becomes a Redis bottleneck, or you don't want to leave the other CUP cores of the server idle?
You can consider several Redis processes. Redis is a key-value database, not a relational database, and there are no constraints between the data. As long as the client can tell which key is on which Redis process.
Advantages and disadvantages of Redis single thread
Advantage 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 CPU consumption due to switching caused by multi-process or multi-thread
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.
IO Multiplexing Technology
Redis uses network IO multiplexing technology to ensure the high throughput of the system when there are multiple connections.
Multiplexing-refers to multiple socket connections, reuse-refers to the reuse of a thread. There are three main techniques for multiplexing: select,poll,epoll. Epoll is the latest and best multiplexing technology at present.
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.
Redis high concurrency fast summary Redis is a pure memory database, which is generally a simple access operation, the thread takes a lot of time, and the time 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. The above is all about the detailed introduction of Redis, thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.