The sudden increase in traffic limiting policy

Think

Since the epidemic, we have to do is Internet education class, so this year we have tripled the flow of goods, but by way of expansion adding machine resources completely Kang Zhu, suddenly thought if it is explosive, if the sudden increase in traffic or even 10 times how to deal with it 20 times? Think carefully about this question for a moment, plus find information, simply wanted to write about what programs.

Scenes

If a system can only accept a maximum amount of concurrent access 10w, and now we have a spike activity, spike activity began when the expected amount of concurrent access to up to 100w. Obviously 100w far more than the normal carrying capacity of the system, how to solve this sudden increase in the flow of it? Starting user access, in fact, requested to go through several stages, we can do the layers of the current limiting for each stage.

The legitimacy of limiting

First of all we think about is this 100w includes normal access users, there is also a malicious user scalping, even some of the robots, then we definitely have to intercept the request and scalping robot, because these requests seriously affected the normal user's purchasing needs. So how limiting it at this level, first of all very simple fact, that is adding a verification code , first of all, this code can block out requests robot, and secondly you can lengthen the user's access time. You can then use the ip restrictions, if found by some network technology under a single request only takes a few milliseconds, or repeat purchase the same commodity, it can request that the user is not considered a legitimate user or a robot, so we can use this ip join blacklist restrictions prohibit access . Finally, the case is not necessarily the case, less than the beginning of the time we do not spike spike address open entrance .

Load limiting

Now, after the first layer of legitimacy limit, there are still about traffic 50w came in, we can use nginx forward traffic to the server cluster, the cluster if we have three machines, each machine only needs to deal with about 17w of the amount of concurrent access. Furthermore, we know that seven layer model according to the network, in the seventh layer Nginx, we can load in other network layer, for example, we load the mac address of the data link layer of the second layer, we can generate a virtual MAC, then this address is mapped to three other servers, the same network can be supported by the ip third layer, the fourth layer in the load port number. Most of us typically use nginx, nginx + lvs or load can be.

Limiting service

Limiting the time the first two levels are reached server's request, then the request to the server when we how to handle it, the first example, we used the tomcat server can limit the number of connections exceeds the number of connections will give up the extra requests, we You can also use a token bucket algorithm, generates only 1000 tokens per second, grab a token request to buy spike merchandise. Taking into account different for each server request-handling capabilities, we can also use message queues to limit the current, can be used to compensate notify the way to inform users buy success. Before and if we use the end of the separation of architecture, user access html and js code can be directly cached in the browser inside picture big points can be saved on nginx or oss cloud server, particularly bulky video can be deployed in cdn above, use It features access to nearby areas to improve the user's access speed, of course, the above cache can complement each other, such as cdn oss server back to the source server. The dynamic data cache is the service end of the business programmers to consider the general use of local cache + redis, but we are not using the more the better cache, cache use, the more possibilities to protect the consistency of the data obtained lower.

Published 169 original articles · won praise 224 · views 260 000 +

Guess you like

Origin blog.csdn.net/sureSand/article/details/105067783