Redis single-threaded architecture and how it works

Source: Internet
Author: User
Tags epoll

One, single-threading model

Each invocation of the Redis client to the server undergoes the sending of a command, which executes the command and returns the result in three processes. Where the command stage is executed, since Redis is single-threaded to handle commands, every command that arrives at the server is not executed immediately, and all commands go into a queue and execute them one after the other. And the order of execution of the commands sent by multiple clients is indeterminate. However, it is certain that no two commands will be executed at the same time without concurrency problems, which is the single-threaded basic model of Redis.

Second, single-threaded model per second of the million-level processing capacity reasons

(1) Pure memory access. The data is stored in memory, and the memory response time is approximately 100 nanoseconds, which is an important foundation for Redis's trillions of accesses per second.

(2) Non-blocking I/o,redis using epoll as I/O multiplexing technology implementation, and Redis's own event processing model will be epoll in the connection, read and write, shutdown is converted to time, not the I/O waste too much time.

(3) Single threading avoids thread switching and race generation consumption.

(4) Redis uses a single-threaded model, and each command executes if it takes a significant amount of time to cause other threads to block, which is fatal for a high-performance service such as Redis, so Redis is a database for high-speed execution.

Iii. Analysis of Redis working mode as a high-performance Key-value database, Redis has the following characteristics:

A variety of data models

Persistence of

Master-Slave synchronization

Redis supports rich data types, the most commonly used data types are five types: String, Hash, List, set, and sorted set. Redis typically stores data in memory or is configured to use virtual memory. One of the most important features of Redis is that it can implement persistent data, which can be persisted in two ways: using an Rdb snapshot to keep the in-memory data written to disk, or logging each update with a aof log method like MySQL. The former performance is high, but may cause some degree of data loss; the latter is the opposite. Redis supports synchronizing data to multiple slave databases, a feature that is useful for improving read performance (although Redis reads writes very quickly, it can also produce very high read pressures.) In order to share the read pressure, Redis supports master-slave replication, and the master-slave structure of redis can be used with a primary multi-slave or cascading structure.

Redis single-threaded architecture and how it works

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.