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 · 2 comments
Open

RateLimiter slowing down with thousand of calls #85

pyrsmk opened this issue Dec 15, 2021 · 2 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`)
})
@sir-george2500
Copy link

did you check the amount of garbage collection that was taken place becase copying array in Javascript uses lot of garbage collection

@pyrsmk
Copy link
Author

pyrsmk commented Sep 23, 2024

Well, it was 3 years ago... If I remember well I implemented my own solution so everything is optimized and runs accurately.

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

2 participants