Skip to content
This repository has been archived by the owner on Apr 19, 2024. It is now read-only.

Feature Request: Atomic Chaining of Limiters #45

Open
colinskow opened this issue Feb 12, 2020 · 2 comments
Open

Feature Request: Atomic Chaining of Limiters #45

colinskow opened this issue Feb 12, 2020 · 2 comments
Assignees
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@colinskow
Copy link

Sometimes when using multiple resources at the same time I want to make sure they are all clear before beginning the work. For example before calling an external API, I want to make sure my own server has capacity to handle the work AND I want to make sure not to abuse the limits of the external API.

I would like to be able to include a chain (list) of limiters in one request. Gubernator would atomically determine if each limiter is UNDER_LIMIT, and only then increment all the hits. If any one of the requested limits is OVER_LIMIT, then the request fails and no hits are incremented.

The response would probably be a Boolean flag of whether the overall request is successful and a list of responses for each limiter requested. The longest reset_time for a failed limiter would be useful as well.

The closest way to achieve this currently is querying each limiter with zero hits to see if they are all open, and only then sending another request to deduct hits from each limiter. The problem is that this operation is not atomic so they could have filled up between requests.

@colinskow
Copy link
Author

Here is an example of this feature in action in another rate limiter:
https://github.com/animir/node-rate-limiter-flexible/wiki/RateLimiterUnion

@thrawn01 thrawn01 self-assigned this May 6, 2020
@thrawn01 thrawn01 added enhancement New feature or request help wanted Extra attention is needed labels May 6, 2020
@thrawn01
Copy link
Contributor

thrawn01 commented May 8, 2020

I've been thinking about this. We could support this by adding a Behavior to the GetRateLimitsReq like so.

message GetRateLimitsReq {
  repeated RateLimitReq requests = 1;
  // Behavior is a set of int32 flags that control the 
 // behavior that applies to all requests
  UnionBehavior behavior = 2;
}

Then a Behavior of ATOMIC_REQUESTS could be added as an option to UnionBehavior

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants