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

Rate limiter with max: 1 having unexpected results #1565

Closed
wootwoot1234 opened this issue Dec 3, 2022 · 1 comment · Fixed by #1570
Closed

Rate limiter with max: 1 having unexpected results #1565

wootwoot1234 opened this issue Dec 3, 2022 · 1 comment · Fixed by #1570

Comments

@wootwoot1234
Copy link

wootwoot1234 commented Dec 3, 2022

We are having issues when we set the rate limiter to:

limiter: {
    max: 1,
    duration: 100
},

It seems to be limiting the jobs more than it should. It's taking much longer to move a job from waiting to active than 1 job every 100ms.

Also, when set it to:

limiter: {
    max: 1,
    duration: 1000/300 // 3.33333333333
},

it stopped processing jobs altogether.

Then in both cases, if we removed the rate limiter, it processed jobs immediately.

but after we use duration: 1000/300, if we add back the duration: 100 limiter, it still didn't process jobs. The only way it would process jobs again was to remove the limiter completely.

We are running Redis version 6.2.6

Has anyone else been successful in setting the rate limiter to max: 1?

@manast
Copy link
Contributor

manast commented Dec 5, 2022

Ok. I realized that PEXPIRE in Redis does not support floats: https://redis.io/commands/pexpire/
This means that the best accuracy we can get is milliseconds. I am adding a fix so that the duration gets floored to the closed millisecond, which in your case means that 3.33 will become 3, so it will process jobs a bit slower than the maximum allowed. Unfortunately, since Redis does not support better accuracy, I do not have a better solution ATM.

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

Successfully merging a pull request may close this issue.

2 participants