An article teaches you how to use Redis easily conceived spike system

Realize the idea spike system with easy Redis

Preface:

System architecture design spike

Spike system, is a typical short burst access a large number of issues. On such issues, there are three kinds of ideas to optimize performance:

** 1. Write memory instead of writing to the hard disk,

  1. Asynchronous processing rather than synchronous processing,

  2. Distributed Processing
    **
    spend these three measures, no matter how much time the load spike, can easily deal with. Better yet, Redis can meet the above three points. Therefore, it can easily achieve with Redis spike system. I use this program, whether it is electronic business platform Special spike, spike train 12306, is not something :)

Here's why these three performance optimization ideas to solve performance problems spike system:

Write memory instead of writing to a conventional hard disk read and write performance is rather poor. The SSD 100 times faster than a conventional hard disk. And the memory off than 10 times faster than the SSD. So, instead of writing to the hard disk into memory, you can upgrade the capacity of the system thousands of times. In other words, the original spike your system may need to support 1000 servers, one server can now Kang Zhu. You may have some questions: write to memory rather than persistent, the data at this time if the computer goes down, so do not write it all lost yet? If you are so unlucky encounter server goes down, then you have no seconds, what is the big deal? Finally, when the real deal behind the spike orders, we will persist information to your hard drive. So you do not lose critical data. Redis is a caching system, after data is written back to memory the client to support this feature.

Sync rather than asynchronous processing such as short-time large spike concurrent system, there is a clear long-term peaks and valleys on the performance load. To cope with quite a short time a large number of servers concurrently prepared to deal with, it is economically very uneconomical. Therefore, the class needs to deal with the spike, it should be of the synchronous to asynchronous. User requests return immediately after writing memory. Background start multiple threads to read data from the asynchronous memory pool for processing. The user request may be entered within 1 second, the actual processing system may take 30 minutes to complete. Then the server in a case where asynchronous processing capability of greater than 1800 times the synchronous case! Asynchronous processing, usually the MQ (Message Queue) is achieved. Redis can be seen as a high-performance MQ. Because it occurred in the data read and write memory.

Well distributed processing. Maybe your customers are many, namely spike system uses a two strokes above, or stretched. It does not matter, we have a big move: distributed processing. If a server barely spike system, then the multi-use several servers. 10 is not, on the table 100. Distributed processing, is the massive user requests across multiple servers. It is generally used to achieve uniform distribution of hash. Such systems have been in big data cloud computing era a lot today. It is nothing more than a Paxos algorithm and Hash Ring implementation. Redis Cluster is such a distributed product.

Redis implemented using the system described

And Redis Redis Cluster (distributed version), is a distributed caching system. It supports a variety of data structures, and also supports MQ. Redis has done a lot in terms of performance optimization. So use Redis Redis Cluster or you can easily achieve a powerful spike system. Basically, you use these commands Redis on it. RPUSH key value inserted spike request

When the inserted spike requests reached the upper limit, stopping all subsequent insertion. Backgrounding multiple worker threads, the successful use LPOP key read spike user id, for subsequent processing. Or reads the user id spike successful use LRANGE key start end command, for further processing. Each finished processing a record spike, on the implementation of INCR key_num. Once all the stock has been processed, it is the end product of this spike, close the thread does not receive spike request.

If still barely holding on, how to do

Perhaps you will say that many of our customers. Even deployed Redis Cluster, still barely. Then how to do it? I remember a great man once said: more solutions than problems!

Below, we analyze the specific, what the situation will overwhelm our system architecture spike on Redis (Cluster) of.

script***

As there are a lot of rush tickets software. They will automatically initiate a http request. The client initiates a one second request many times. If there are many users use this software, you can switch to direct our overwhelmed.

In fact, this problem belongs to the category of network problems, and our system is not a spike on the level. And therefore it should not be resolved by us. Many switches have a function to prevent a source IP initiate excessive requests. There are many open source software can achieve this. The TC can be controlled on the linux. Popular Web server Nginx (it can also be seen as a seven soft switch) can also be configured to do this. An IP, for a second I'll allow you to visit me twice, directly to other software packages you lose, you can overwhelm me?

Switch barely

Your customers may access the amount of concurrent too great, switches barely. This is also a way. We can use multiple switches serve our spike systems. Principle is that DNS can return multiple IP addresses to a domain name, and different source IP, IP returned with a different domain name. As users access Netcom, China Netcom will return to a room IP; users access to telecommunications, it returns a telecommunications room IP. It is to use a CDN! We can deploy multiple switches for different users. Redis spike operation by a user switches the access after the data center Cluster.

Summary

With Redis Cluster's help, to be a support system in fact massive user spike So Easy! Although the scheme is introduced for the spike system, but the principle behind it is as effective as other highly concurrent systems here. Finally, let us remind ourselves of the principle of optimization of high-performance systems: write to memory rather than written to disk, instead of asynchronous processing synchronous processing, distributed processing.

Will share daily java-related articles to help me remember the point of a concern oh

Guess you like

Origin blog.51cto.com/14456091/2424533