Home > Database > Redis > Redis is single-threaded but why is it so efficient?

Redis is single-threaded but why is it so efficient?

(*-*)浩
Release: 2019-11-21 14:34:56
Original
3749 people have browsed it

Redis is single-threaded but why is it so efficient?

This does not need a variety of locks of performance consumption (Recommended learning: redis video tutorial )

## Redis data structure It is not all simple Key-Value, but also complex structures such as list and hash. These structures may perform very fine-grained operations, such as adding an element after a long list, adding or deleting an object from the hash. . These operations may require adding a lot of locks, resulting in a greatly increased synchronization overhead.

In short,

In the case of a single thread, there is no need to consider various lock issues. There is no locking and releasing lock operations, and there is no performance consumption caused by possible deadlocks.

Single-threaded multi-process cluster solution

The power of single-threading is actually very powerful, and the efficiency of each core is also very high. Multi-threading is naturally better than single-threading. Threads have a higher performance limit, but in today's computing environment, even the upper limit of single-machine multi-threading often cannot meet the needs. What needs to be further explored are multi-server clustering solutions. The multi-threading technology in these solutions is still the same. It's useless.

So single-threaded, multi-process cluster is a fashionable solution.

CPU consumption

Uses a single thread to avoid unnecessary context switching and competition conditions, and there is no switching caused by multi-process or multi-threading Consumes CPU.

But what should we do if the CPU becomes the bottleneck of Redis, or we don’t want other CPU cores of the server to be idle?

You can consider starting several more Redis processes. Redis is a key-value database, not a relational database, and there are no constraints between data. As long as the client distinguishes which keys are placed in which Redis process, it will be fine.

The above is the detailed content of Redis is single-threaded but why is it so efficient?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.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