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

rate limit #145

Merged
merged 11 commits into from
Nov 27, 2023
Merged

rate limit #145

merged 11 commits into from
Nov 27, 2023

Conversation

ermalkaleci
Copy link
Collaborator

No description provided.

@ermalkaleci ermalkaleci requested a review from xlc November 26, 2023 20:41

#[derive(Deserialize, Debug, Copy, Clone, Default)]
pub struct RateLimitConfig {
pub burst: u32,
Copy link
Member

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

}

fn default_request_timeout_seconds() -> u64 {
120
}

#[derive(Deserialize, Default, Debug, Copy, Clone)]
#[serde(rename_all = "snake_case")]
pub enum Period {
Copy link
Member

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we can

Copy link
Member

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

pub burst: u32,
pub period: Period,
#[serde(default = "default_jitter_millis")]
pub jitter_millis: u64,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this?

Copy link
Collaborator Author

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

Copy link
Member

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
Copy link
Member

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

Copy link
Collaborator Author

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

Copy link
Member

@xlc xlc Nov 27, 2023

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,
}

config.yml Outdated Show resolved Hide resolved
@xlc xlc merged commit 43cbd17 into master Nov 27, 2023
1 check passed
@xlc xlc deleted the rate_limit branch November 27, 2023 23:17
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

Successfully merging this pull request may close these issues.

2 participants