Open colinskow opened 4 years ago
Here is an example of this feature in action in another rate limiter: https://github.com/animir/node-rate-limiter-flexible/wiki/RateLimiterUnion
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
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.