Common current-limiting algorithms are: Token bucket, leaky bucket, counter.
Token bucket Current limit
The token bucket is a bucket that holds a fixed capacity token , adds a token to the bucket at a fixed rate , fills in the discard token, requests whether it is processed to see if the token is sufficient in the bucket, and rejects the new request when the number of tokens is reduced to zero. The token bucket allows for a certain amount of bursts, as long as there is a token to handle, support to take multiple tokens at once. a token is loaded in the token bucket .
Leaky Bucket limit Flow
A fixed-capacity leaky bucket that flows out of a request at a fixed constant rate , at any rate of incoming requests, and when incoming requests accumulate into leaky bucket capacity, the new incoming request is rejected. A leaky bucket can be seen as a queue with a fixed capacity, a fixed outflow rate, and a leaky bucket limit of the requested outflow rate. The leaky bucket is loaded with a request .
Counter Current limit
It is mainly used to limit the total concurrency in a certain period of time, such as database connection pool, thread pool, and the number of seconds to kill; The counter current limit, as long as the total number of requests in a certain amount of time exceeds the set threshold, is a simple rough total quantity limit , not the average rate current limit .
Current limiting algorithm