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

Redis is the reason for single thread

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

This article is to share with you about the reason why redis is single-threaded, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.

Introduction to redis

It's a key-value storage system. Similar to Memcached, it supports relatively more value types, including string (string), list (linked list), set (collection), zset (sorted set-ordered collection), and hash (hash type). These data types support push/pop, add/remove, and take intersection union and difference sets, and richer operations, and these operations are atomic. On this basis, redis supports a variety of different sorting methods. Like memcached, data is cached in memory for efficiency. The difference is that redis will periodically write updated data to disk or modify operations to additional record files, and on this basis to achieve master-slave (master-slave) synchronization.

Simple analysis:

Redis is a memory-based operation, CPU is not the bottleneck of Redis, the bottleneck of Redis is most likely to be the size of machine memory or network bandwidth. Because single-threading is easy to implement and CPU does not become a bottleneck, it makes sense for redis to adopt a single-threaded solution.

Details of the reasons:

1. 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.

2. Do not need the performance consumption of various locks

The data structures of Redis are not all simple Key-Value, but also complex structures such as list,hash, which may perform very fine-grained operations, such as adding an element after a long list and adding or deleting an object in the hash. 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.

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.

These are the reasons why redis is single-threaded, and the editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please 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.

Share To

Database

Wechat

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

12
Report