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

Optimize rate limit using Lua script #5920

Open
cuongtd1301 opened this issue Jan 4, 2024 · 0 comments
Open

Optimize rate limit using Lua script #5920

cuongtd1301 opened this issue Jan 4, 2024 · 0 comments

Comments

@cuongtd1301
Copy link

cuongtd1301 commented Jan 4, 2024

Is your feature request related to a problem? Please describe.
I have the same issue with this #1876
I see rate limiting as an important feature that should be implemented as a separate function instead of using a shared function (SetRollingWindow, GetRollingWindow) with other functionalities, which can result in resource waste

Describe the solution you'd like
After researching, I have decided to optimize the rate limit feature by using a Lua script for Redis. For more details, please refer to the pull request #5921

Additional context
I have built a sample API to compare the rate limit before and after the improvement. With a per value of 300, rate value of 60, and a server firing a load with 5 worker pools and 20k requests:

With the original rate limit, it takes 60 seconds to complete. The CPU usage increases by 60%, and the sorted set reaches 2MB with nearly 20k keys.

image
image

With the improved rate limit, it only takes 6 seconds to complete. The CPU usage peaks at 6%, and the sorted set size is reduced to 1KB with 60 keys.
image
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant