-
Notifications
You must be signed in to change notification settings - Fork 46
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
Combination of rate_limiters #156
Comments
Thanks for posting this - I've been thinking about something like this all that time (it's a bit similar to #131, but not similar enough to warrant the same solution!). The idea I had just now was that we could expose an internal method on rate limiters, that allows undoing a positive decision, effectively removing its weight from the bucket & restoring burst capacity. This could be used by a Some trade-offs there:
What do you think? |
Not a big fan of having an "undo" method. You want the user of your API to be shielded from this complexity. Yeah, I prefer an atomic approach. Not sure if mutexes are that bad in this context. They can be pretty fast nowadays. |
I agree with @praetp here. An |
I think there is a use case you want to protect a resource with multiple rate limiters. E.g. one direct and one keyed or multiple keyed.
Example usecase:
You cannot just consecutively call
check()
orcheck_key()
because it will be a mess if you only have partial success. E.g. if you have two rate limiters and the firstcheck()
returns a positive outcome, and the second one in a negative outcome, you cannot continue but you have spent some of the first rate limiter's quota regardless.Morever, the current architecture does not allow you to easily have different quotas (you have to make a different rate limiter then).
I am not sure how to solve it.
Maybe we have to introduce a third type of RateLimiter: the DictionaryRateLimiter.
For a given set of
(key, value)
pairs, it accepts aQuota
, at construction time.Example
The usage would then be:
This last function call would only have a positive outcome if all quotas for the different 'levels' (i.e. "api", "usergroup", "user") are satisfied.
Let me know what you think.
The text was updated successfully, but these errors were encountered: