-
Notifications
You must be signed in to change notification settings - Fork 589
new token bucket impl #6893
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: master
Are you sure you want to change the base?
new token bucket impl #6893
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #6893 +/- ##
=========================================
- Coverage 83.2% 83.2% -0.1%
=========================================
Files 856 856
Lines 376837 377166 +329
=========================================
+ Hits 313736 313969 +233
- Misses 63101 63197 +96 🚀 New features to boost your workflow:
|
|
||
/// Provides rate limiting for multiple source IP addresses | ||
/// on demand. Uses LazyLru under the hood. | ||
pub struct KeyedRateLimiter { |
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.
Shouldn't it be Sync+Send if we want to use it in different tasks? I'm not sure if LazyLru is.
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.
probably yes, will work on it.
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.
Done in adcf32e The implementation is kinda naive and performance is not amazing, but it is simpler and also accurate (unlike the governor crate based impl)
/// Provides rate limiting for multiple source IP addresses | ||
/// on demand. Uses LazyLru under the hood. | ||
pub struct KeyedRateLimiter { | ||
data: RwLock<LruCache<IpAddr, TokenBucket>>, |
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.
yeah, governer is using DashMap<IpAddr, Atomicu64>
and i think we do something similar here for the performance sake (depends on when do we need this, of course).
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.
Yeah switching to a sharded hashmap would be the most obvious thing to optimize. Time to fork LazyLRU?
4579fe3
to
aa91a89
Compare
aa91a89
to
58d47a2
Compare
Problem
Summary of Changes