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

'Stricter' rate limiter #322

Open
guersam opened this issue Mar 1, 2023 · 3 comments
Open

'Stricter' rate limiter #322

guersam opened this issue Mar 1, 2023 · 3 comments

Comments

@guersam
Copy link

guersam commented Mar 1, 2023

I have a rate limit requirement for a third party API.

At first it sounded very easy with rezilience. But when I tested against the real server, several requests were blocked due to the rate limit. I've tried manually setting burst to 0, but had no luck.

Here's a minimal reproduction:

$ scala-cli https://gist.github.com/guersam/5ecccfb84c0d6c0f39f3182f91bacdc1

Expected Result

Given rate limit of 10 per second, the second 10 timestamps should be at least 1 second from start because the limit of 10 is already reached within the first second

Actual Result

The 11th elements is emitted even before 0.3 seconds

Related issue

zio/zio#7888

@svroonland
Copy link
Owner

Hi @guersam, do you still experience this issue with the latest ZIO version?

@guersam
Copy link
Author

guersam commented Apr 17, 2023

@svroonland Yes, because it's intended behavior of throttleShapeZIO.

I ended up with writing my own sliding window pipeline and it just works. If you think sliding window is more suitable than token bucket for rate limiters, I'm willing to contribute my implementation as well.

@svroonland
Copy link
Owner

@guersam I'd be interested in that implementation, definitely. Apologies for the late reply. Looking forward to a PR!

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