-
Notifications
You must be signed in to change notification settings - Fork 26
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 limit #145
rate limit #145
Conversation
src/extensions/server/mod.rs
Outdated
|
||
#[derive(Deserialize, Debug, Copy, Clone, Default)] | ||
pub struct RateLimitConfig { | ||
pub burst: u32, |
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.
needs some comments explain the parameters as it is not super clear to me
src/extensions/server/mod.rs
Outdated
} | ||
|
||
fn default_request_timeout_seconds() -> u64 { | ||
120 | ||
} | ||
|
||
#[derive(Deserialize, Default, Debug, Copy, Clone)] | ||
#[serde(rename_all = "snake_case")] | ||
pub enum Period { |
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.
do we only able to support those 3 periods? can we just support arbitrary seconds?
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.
Yes we can
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.
in that case make an input like period_seconds
and we don't need this enum
src/extensions/server/mod.rs
Outdated
pub burst: u32, | ||
pub period: Period, | ||
#[serde(default = "default_jitter_millis")] | ||
pub jitter_millis: u64, |
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.
what is this?
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.
Random additional delay so delayed request won't be fired at the same time. If jitter 100ms they are spread between wait_time + rand(0-100)ms
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.
I see. looks useful but need comments
config.yml
Outdated
@@ -23,6 +23,9 @@ extensions: | |||
- path: /liveness | |||
method: chain_getBlockHash | |||
cors: all | |||
rate_limit: | |||
burst: 20 |
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.
this is 20 requests per second?
also in future, I would like to have more limiting options.
e.g.
requests per period per IP
requests per period per connection
new connections per period IP
and I would like to put this under etensions, instead of part of the server config mainly to reduce the LOC under server
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.
Yes sure. This is more an initial version
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.
what I am asking is to make the config to be something like
rate_limit: Vec<RateLimitRule>
struct RateLimitRule {
key: Vec<RateLimitKey>,
period_seconds: u32,
quota: u32,
}
enum RateLimitKey {
Connection.
IP,
Unit,
}
No description provided.