Skip to content

RateLimiter slowing down with thousand of calls #85

@pyrsmk

Description

@pyrsmk

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`)
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions