I'm currently faced with a challenge where I need to work out the rate number for a rate limiter (either using Google Guava or resilience4j rate limiter) so that it can handle throttling the API within the limit threshold, statistics listed below:
- Input: 10,000 requests
- API limit: 100 requests per minute
I'm struggling to work out the formula to calculate this with the numbers listed above. If anyone could help me out, that would be greatly appreciated. Thanks.
CodePudding user response:
The guava rate limiter operates on permits per second.
So your 100 per minute is 100 per 60 seconds.
Set the rate at 100.0/60.0 = 1.66667
The .0 is important in that calculation to make sure it's worked out as a floating-point fraction in Java.
As an aside 10,000 requests at 100 requests per minute will take 10,000/100 minutes. That's 100 minutes (1 hour 40 minutes) to complete.
In practice bottlenecks and bursts may mean you exceed the advertised rate limit. You might end up dialing back to say 90 per minute (1.5 per second) to make sure you never hit the limit.