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