What is the traffic peak clipping? How to solve the business clipping scene spike

The origin of traffic clipping

Mainly comes from the Internet business scenarios, for example, immediately upcoming Spring Festival rush to buy train tickets, a large number of users need the same time to buy; as well as the well-known double spike 11, the short-term influx of millions of users Ali, instantaneous flow huge (high concurrency), for example: 200 people ready to buy a piece of merchandise ready at 12:00 am, but the number of missing items is limited around 100-500 pieces.

In this way the user can purchase real items is only about a few hundred people, but from the business, the spike activity is hope more people to participate, that is, want to have before buying more and more people look to buy goods .

However, after buying time to reach, when the user starts the real orders, the server back-end spike of shortage of millions of people at the same time do not want to buy at the same time initiating the request.

We all know the server's processing resources are limited, so when the peaks can easily lead to server downtime, users can not access the situation arise.

It's like time travel problems and evening peak of the morning rush hour, in order to solve this problem, there is a solution for peak load shifting travel limit line.

Similarly, spike and other business scenarios on the line, also need similar solutions need to weather problems while buying traffic spikes caused by, and this is the origin of traffic clipping.

file

How to achieve the flow clipping scheme

Clipping essence is more delay requested by the user, as well as layers of filtering access needs of users, to comply with the "last fall to several requests to the database as little as possible" principle.

1. Message Queuing resolve clipping

To traffic clipping, most obvious solution is to use the message queue to buffer flow rate, synchronous call directly converted into asynchronous push indirectly, through an intermediate queue receiving a peak instantaneous flow rate at one end, the other end of the smoothing to push the message out.

file

Message Queue Middleware is mainly to solve application coupled, asynchronous messaging, traffic cut front and other issues. Common message queue system: Currently in production, the use of message queues have more ActiveMQ, RabbitMQ, ZeroMQ, Kafka, MetaMQ, RocketMQ and so on.

Here, the message queue is like "Reservoir", as storing flood upstream, downstream river cuts into the peak flow, so as to achieve the purpose of flood disaster relief.

2. Flow clipping funnel: clipping layers

There is also a method for the spike scenario, the request is layered filter, which filter out invalid request.

Layered filter is actually a "funnel" type designed to handle the request, as shown below:

file

Such as a funnel, as far as possible the amount requested and the amount of data in layers and reduced filtration.

1) layered filter core idea

  • Invalid request by filtration at different levels as much as possible out.
  • Filter out a lot of pictures by CDN, requests for static resources.
  • Then a read request by a similar Redis such a distributed caching, filtering requests is a typical upstream interception.
2) Basic principles of layered filter

  • Write data slice based on a reasonable time, to filter out invalid request expired.
  • Do limit protection, the request would exceed the carrying capacity of the system to filter out the write request.
  • The read data is not related to the stronger consistency check, the consistency check as to reduce the problem of bottlenecks.
  • Write strong data consistency check, leaving only the last valid data.
  • Finally, let the "funnel" the very end (database) is a valid request. For example: when a user reaches the real process orders and payments, this is a strong need for consistency of data.

Clipping traffic summary

1. For such a high spike concurrent business scenario, the basic principle is to intercept the requests in the system upstream, downstream pressure reduction. If you do not intercept is likely to cause the front end of a database (mysql, oracle, etc.) read-write lock conflicts, and even lead to a deadlock, the final scene there are avalanches may occur.

2. The good news division resources, the use of static resources were CDN service delivery.

3. To make full use of cache (redis, etc.): increase QPS, thereby increasing the throughput of the entire cluster.

4. The peak flow system is overwhelmed very important reason, it is necessary to undertake the message queue Kafka et peak instantaneous flow rate at one end, at the other end to smoothly push out the message.

Published 81 original articles · won praise 46 · views 9391

Guess you like

Origin blog.csdn.net/weixin_43649691/article/details/103425328