-
Notifications
You must be signed in to change notification settings - Fork 1.7k
En/rate limiter #2263
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
base: development
Are you sure you want to change the base?
En/rate limiter #2263
Conversation
@Umang01-hash We should consider having support for generic time window, i.e. not limit to per second. Most systems have per minute/hour limits. |
71e1f9b
to
aae16f3
Compare
@akshat-kumar-singhal sure fixed the same Users can use it like:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
Validate Window ≥1 ms
Prevent micro/nanosecond windows that spike CPU and precision issues:
if config.Window<time.Millisecond { return fmt.Errorf("min window 1ms, got %v",config.Window) } -
RPS Calculation
Avoid repeated division: compute once and reuse cachedRPS. -
Preload Lua Script
Load script SHA on init and use EVALSHA to skip re-compiling on every Redis call.
8f5b4bb
to
29b15e2
Compare
v2 was released in August 2023 to use the Go Protobuf v2 API. We only use the recovery interceptor so we are not affected by the breaking changes. Reference: https://github.com/grpc-ecosystem/go-grpc-middleware/releases/tag/v2.0.0 Signed-off-by: Eng Zer Jun <[email protected]>
…> for clarity and consistency
Add Rate Limiting Support for HTTP Services
This PR adds rate limiting capabilities to # Add Rate Limiting Support for HTTP Services
This PR adds rate limiting capabilities to GoFr's HTTP service clients using the token bucket algorithm. It provides both local (in-memory) and distributed (Redis-based) implementations to suit different deployment scenarios.
Features
Two Implementation Strategies:
Core Features:
Usage Example
Usage Screenshots:
Checklist:
goimport
andgolangci-lint
.Thank you for your contribution!