Home > Database > Redis > Why redis has good performance

Why redis has good performance

(*-*)浩
Release: 2019-11-22 10:56:43
Original
2425 people have browsed it

Why redis has good performance

#redis is a non-relational in-memory database. Data is stored in memory, and memory reading speed is very fast. If it is just a simple key-value, memory is not the bottleneck. Generally, hash searches can reach the order of millions of times per second. (Recommended learning: Redis Video Tutorial)

Using a single thread to avoid unnecessary context switching and race conditions

The internal implementation uses epoll , using a simple event framework implemented by epoll itself. Read, write, close, and connect in epoll are all converted into events, and then use the multiplexing feature of epoll to never waste any time on io

Because Redis operations are very fast— —All its data is in memory, and there is no need to access the disk at all. As for concurrency, Redis uses multi-channel I/O multiplexing technology, and its own concurrency efficiency is not a problem.

Of course, a single Redis process cannot use multiple cores (it can only run on one CPU core at any time), but it is not a very computationally intensive service. If the single-core performance is not enough, you can open several more processes.

Redis adopts a single-threaded model to ensure the atomicity of each operation and reduce thread context switching and competition.

In addition, the data structure also helps a lot. Redis uses hash structure throughout the process, which has fast reading speed. There are also some special data structures that optimize data storage, such as compressed tables, Compress and store short data, another example is jump tables, and use ordered data structures to speed up reading.

Another point is that Redis uses its own event separator, which is relatively efficient. It uses a non-blocking execution method internally and has a relatively large throughput capacity.

string type, binary safe

hash type, is a collection of key-value pairs

The bottom layer of the List list is a linked list

set collection No need to implement

zset sort set ordered set through hashtale

For more Redis-related technical articles, please visit the Redis database usage tutorial column to learn!

The above is the detailed content of Why redis has good performance. 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