Why is the Redis a single thread?

Source: Internet
Author: User
Tags data structures redis

Simple Network IO, the volume to a certain extent, multithreading do have advantages, but not simple multithreaded, but each thread has its own epoll such a model,

That is, multithreading and multiplexing mixing. But. Also consider the Redis operation is in-memory data structure. If you operate in multiple threads, you need to lock these objects.

So using multithreading can improve performance, but the efficiency of each thread is severely reduced, and the logic of the program is seriously complicated. Redis's data structures are not all simple key-value,

There are complex structures, such as list,hash, that are likely to perform fine-grained operations, such as adding an element after a long list, adding or deleting a hash

An object that can also synthesize multi/exec groups. A very large number of locks may be required in such an operation, resulting in a significant increase in synchronization overhead. Redis

After weighing the choice is to use a single thread, highlighting the flexibility of their functions. Any atomic operation on a single thread basis can be implemented almost without cost, and how complex data structures are

Can be easily used, even with features such as LUA scripts. For multiple threads This requires a much higher price.

Not all KV database or memory database should use a single thread, such as zookeeper is multi-threaded, and ultimately to see the author's own will and choice. Single Thread

The power is actually very strong, each core efficiency is also very high, in today's virtualized environment can take full advantage of the cloud environment to improve resource utilization. Multithreading naturally can be compared to single

Thread has a higher performance limit, but in today's computing environment, even the upper limit of multithreading is often unable to meet the needs, the need to further explore the multi-server clustering

Solution, the multithreading technology is still not used in these scenarios, so the single threaded, multi process cluster is a fashionable solution.

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.