SGrondin / bottleneck

Job scheduler and rate limiter, supports Clustering
MIT License
1.84k stars 79 forks source link

Need help applying multiple limiters #196

Open viktorgullmark opened 3 years ago

viktorgullmark commented 3 years ago

Hey, didnt know where to turn exactly but I didnt see this covered in the docs.

I want to comply to the following headers: x-rate-limit: 15:10:60,30:300:300.

I have tried doing so by setting up the following and chaining them:

const limiter1 = new Bottleneck({ reservoir: 30, reservoirRefreshAmount: 30, reservoirRefreshInterval: 300 * 1000, maxConcurrent: 1, minTime: 500, });

const limiter2 = new Bottleneck({ reservoir: 15, reservoirRefreshAmount: 15, reservoirRefreshInterval: 10 * 1000, maxConcurrent: 1, minTime: 500, });

const chained = limiter1.chain(limiter2);

Since I create these at the same time, the reservoirRefreshInterval keeps ticking for the second limiter when its stuck waiting on the first one, so in theory too many requests could be sent in a shorter timespan.

Is there any way of complying to multiple limits like this?

Thanks