-
Notifications
You must be signed in to change notification settings - Fork 17.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
proposal: x/time/rate: Add Sliding window, Fixed window, and Leaky bucket rate limiters #44324
Comments
There are a lot of different features you may or may not want in a rate limiter. Features come with tradeoffs like dependencies or memory usage etc. The
My feeling is that this proposal would carry more weight if: (A) It proposed a uniform interface. I'd think you should start with (A). |
As part of the examination of as such I have two options as starting points, The first type Limiter interface {
AllowN(now time.Time, n int) bool
ReserveN(now time.Time, n int) Reservation
WaitN(ctx context.Context, n int) error
}
type Reservation interface {
CancelAt(now time.Time)
DelayFrom(now time.Time) time.Duration
OK() bool
} Is effectively a slimmed down version of the current implementation, and really only differs in what it removes from my original messing around in that it removes the helpers. The second is a much more radical change to the way type Limiter interface {
Allow(time.Time, int) bool
Reserve(time.Time, int) Reservation
}
type Reservation interface {
Cancel(context.Context)
Ready() <-chan bool
ExpectedDelay(time.Time) time.Duration
Delay(time.Time) time.Duration
OK() bool
}
From smallest to largest, the other changes are as follows
|
Is your feature request related to a problem? Please describe.
When interacting with an external API that has a rate limiter implemented, it is important to have a matching rate limiter so that requests aren't unintentionally triggering that rate limit.
Describe the solution you'd like
Implementation of
rate limiting algorithms.
Describe alternatives you've considered
Some of these algorithms exist under external repositories
but the ideal would be for a common interface and location for these algorithms
Additional context
I requested the creation of a common interface in #43003 but I put the cart before the horse.
As with any request, the initial goal is to determine which, if any of these are worth implementing, and in what form.
The text was updated successfully, but these errors were encountered: