Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RateLimiter slowing down with thousand of calls #85

Open
pyrsmk opened this issue Dec 15, 2021 · 0 comments
Open

RateLimiter slowing down with thousand of calls #85

pyrsmk opened this issue Dec 15, 2021 · 0 comments

Comments

@pyrsmk
Copy link

pyrsmk commented Dec 15, 2021

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`)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant