jhurliman/node-rate-limiter

RateLimiter slowing down with thousand of calls

pyrsmk opened this issue · 0 comments

I encounter an issue where when I spawn a whole bunch of limiter instances (several thousands). At first, the rate limit is pretty accurate, but at some point it begins to freeze every now and then. And it gets slower and slower.

Here's a clear example of what's going on:

const { RateLimiter } = require('limiter')
const limiter = new RateLimiter({ tokensPerInterval: 1, interval: 100 })

let index = 0
const newIndex = () => ++index;

[...Array(5000).keys()].forEach(async () => {
  const idx = newIndex()
  console.log(`[${idx}] awaiting`)
  await limiter.removeTokens(1)
  console.log(`[${idx}] delivered`)
})