Site Current limit Processing

Source: Internet
Author: User

1. Common two ways of leaky bucket algorithm and token bucket algorithm

Leaky bucket algorithm: 1. There is a fixed capacity of the leaky bucket, the fixed rate of outflow of water droplets.

2. Can flow into the leaky bucket at any rate

3. When the leaky bucket is full, water overflows (equivalent to discarding)

Token bucket algorithm:

1. Place the token in the bucket at a fixed rate

2. When the number of tokens in the bucket reaches the maximum, subsequent tokens are discarded

3. When you need to send n unit-size data, go from within the bucket n tokens

4. When the number of tokens in a bucket is less than the set size, the token cannot be deleted, that is, the data cannot be sent, which may be discarded or cached by the buffer.

2. Other methods

Statistical counting, the main idea is to record the number of visits within a specified time, and then periodically clear the count.

The statistical count method can be implemented using Jedis's incr and expire APIs, or by using concurrent maps.

Configuring current limit in Nginx

3. Open Source Implementation

Guava Ratelimiter, based on the token bucket algorithm implementation of the specific usage reference http://ifeve.com/guava-ratelimiter/

Site Current limit Processing

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.