Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Limiter ¶
type Limiter struct {
// contains filtered or unexported fields
}
Limiter is a simple rate limiter to control how frequently events are allowed to happen. It trades some accuracy on resets for speed.
func (*Limiter) IsAllowed ¶
IsAllowed returns whether n events may happen now. NB(xichen): If a large request comes in, this could potentially block following requests in the same second from going through. This is a non-issue if the limit is much bigger than the typical batch size, which is indeed the case in the aggregation layer as each batch size is usually fairly small. The limiter is racy on window changes, and can be overly aggressive rejecting requests. As the limits are usually at least 10k+, the error is worth the speedup.