jhurliman/node-rate-limiter

Possible to adjust concurrency?

Closed this issue · 2 comments

zeke commented

Hi. I'm hitting the GitHub API using this setting:

const limiter = new RateLimiter(5000, 'hour')

This is within GitHub's documented limit, but I'm still getting throttled because limiter is making so many concurrent requests. I think this is happening because limiter comes on strong at first and uses some kind of backoff mechanism to taper down the requests over the course of the hour. Is that right?

Is there a way to limit the number of concurrent requests?

Here's one way I'm thinking I could approximate it:

const limiter = new RateLimiter(Math.floor(5000/60), 'minute')
// or
const limiter = new RateLimiter(Math.floor(5000/60/60), 'second')

The best way to handle this is by using the lower level TokenBucket API. It allows burst rate and fill rate to be configured separately, and you can nest them so an 80/minute bucket can have a parent with a 5000/hour limit.

zeke commented

Thanks for the info @jhurliman. I ended up having pretty good luck just using a smaller time increment.