[Back-end tutorial] How to ensure that the system is not overwhelmed by sudden traffic?

Author l will be the code uncle (CodeDaShu)

To ensure the high availability of the system, there are a lot of things to do, such as using Redis to cache the data of the database to reduce the pressure on the database, and also pay attention to the problems of cache penetration, avalanches, breakdown, etc .; "Traffic is overwhelming", usually to the three-axe of the distributed architecture we often say: current limiting, fusing, and downgrading.

01

Limiting

The current limit is very simple to understand. For example, the Forbidden City only sells 80,000 tickets per day, and more than 80,000 tourists cannot buy tickets to enter, because if more than 80,000 people, the staff of the attraction may be too busy, too crowded attractions It will affect the experience and mood of tourists, and there will also be hidden dangers; only sell N tickets, this is a means of limiting current.

The same is true for the current limit in the software architecture, that is, when the flow increases, only a part of the flow is allowed to come in, and the excess part is rejected.

Usually we can achieve this effect through the current limiting algorithm, such as counter method, sliding window method, leaky bucket algorithm, token bucket algorithm. The detailed explanation of each algorithm has been introduced in the previous article, and it will not occupy space here. In the above example, the Forbidden City only sells 80,000 tickets per day, which is a bit similar to the token bucket algorithm. Tickets are equivalent to tokens. Only when a request is obtained can the service be accessed.

In addition, the current limit can be limited for different systems or business processes. For example, the core system A needs to limit the current. The B system calls the A system is very important, and the C system calls the A system is relatively less important, so when the A system does not support When you live, you can limit the number of calls to the C system to ensure the stable operation of the B system.

image

02

Fuse

In real life, the role of a fuse is to blow, and it can automatically trip when a short circuit occurs to protect home appliances.

In most of our application scenarios, there are many scenarios where the A system adjusts the B system interface and the B system then adjusts the C system interface. This is the calling link: A-> B-> C-> D; The upper limit is definitely different. For example, the traffic increases, the D system has reached the upper limit of the load, and the interface response of the D system is very slow. This may cause the A / B / C to call it and wait for a timeout; The link avalanche has changed from a service failure to multiple system failures.

At this time, the fuse comes in handy. If a large number of requests time out in a short time, it means that the system has failed, so there is no need to access this service. At this time, use fuse to disconnect this Links.

The fuse can also automatically diagnose the status of the downstream service. If the service is restored, then slowly release the request until the state before the fault occurs.

image

03

Downgrade

Service degradation can be automatically determined by code. For example, as mentioned in the service flow limitation above, when traffic increases, you can limit the access of unimportant systems or services. Which system is important and which system is not important is the service. The distinction between grades and levels, when the number of visits increases, low-level systems can be automatically downgraded.

Service degradation can also be manually switched according to unexpected situations; for example, when certain service nodes (such as Double 11, 618), in order to ensure the normal operation of shopping and payment, some unimportant services will be disabled; even in extreme cases When shopping and payment can only choose one, shopping is more important, so you can prepay or delay payment in advance.

image

In short, current limiting, melting point and degrading are all means to ensure system stability when the flow increases excessively and is too large.

Service recommendation

Published 0 original articles · liked 0 · visits 333

Guess you like

Origin blog.csdn.net/weixin_47143210/article/details/105681814