Redis (ii)----Single-threaded architecture

Source: Internet
Author: User
Tags epoll

Redis is a NoSQL database based on key-value pairs (key-value), which contains a variety of data structures. The number given on official web is read and write performance can reach 100,000/sec, visible speed.

As a simple example, open 5 Redis clients simultaneously, and execute the following command:

INCR number  

Each command is executed in the same way, sending commands, executing commands, and returning results.

In the case of multithreading, no processing is likely to cause problems with the final result of the data. But Redis will not, Redis is a single-threaded approach, the new command will not be executed immediately, but unified into the queue, a piece of execution.

There is no concurrency problem with such a process. Then why is it so fast in a single thread? Generally speaking, single-threaded processing is less than multithreading, for example: 10000 kg of cargo, each vehicle carrying capacity is 1000 kg, then if only one car will need 10 times to complete, but if there are 10 cars, one can be completed.
Then why does Redis use a single-threaded model to achieve a per-second level of processing capacity. Boils down to the following three points:

1, pure memory access, Redis all the data into the memory, the memory response time of about 100 nanoseconds, which is redis can have millions processing capacity of the important basis.
2, there is also a point is that Redis adopted the epoll as I/O multiplexing technology implementation. At the same time, Redis's own event-handling model converts the connection, read-write, and shutdown in Epoll to events and consumes too much time on network I/O. This will be explained in more detail in the following blogs.
3, single-threaded reduce the thread switching and the consumption of the resulting state.

     But a single thread also has a problem: it is a requirement for the execution time of each command, and if one of the commands is too long, it can cause other commands to block, which is fatal to redis this high-performance service. So Redis is a database for fast-executing scenarios.

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.