NewTokenBucketRateLimiter creates a rate limiter which implements a token bucket approach. The rate limiter allows bursts of up to 'burst' to exceed the QPS, while still maintaining a smoothed qps rate of 'qps'. The bucket is initially filled with 'burst' tokens, and refills at a rate of 'qps'. The
(qps float32, burst int)
| 47 | // The bucket is initially filled with 'burst' tokens, and refills at a rate of 'qps'. |
| 48 | // The maximum number of tokens in the bucket is capped at 'burst'. |
| 49 | func NewTokenBucketRateLimiter(qps float32, burst int) RateLimiter { |
| 50 | limiter := rate.NewLimiter(rate.Limit(qps), burst) |
| 51 | return newTokenBucketRateLimiter(limiter, realClock{}, qps) |
| 52 | } |
| 53 | |
| 54 | // An injectable, mockable clock interface. |
| 55 | type Clock interface { |