feat: Configurable rate limiter max burst size (#28)

Signed-off-by: Jagoda Ślązak <jslazak@jslazak.com>
This commit is contained in:
Jagoda Estera Ślązak
2026-01-28 17:47:48 +01:00
committed by GitHub
parent 9a8e4fe65c
commit 23231d462c
2 changed files with 11 additions and 1 deletions
+9
View File
@@ -17,7 +17,10 @@ pub struct Config {
pub postfix_reinject_port_incoming: u16,
#[serde(default = "Config::default_max_message_size")]
pub max_message_size: usize,
#[serde(default = "Config::default_max_user_send_per_minute")]
pub max_user_send_per_minute: NonZeroU32,
#[serde(default = "Config::default_max_user_send_burst_size")]
pub max_user_send_burst_size: NonZeroU32,
#[serde(default, deserialize_with = "deserialize_sequence")]
pub passthrough_senders: Vec<String>,
#[serde(default, deserialize_with = "deserialize_sequence")]
@@ -94,4 +97,10 @@ impl Config {
const fn default_max_message_size() -> usize {
31457280
}
const fn default_max_user_send_per_minute() -> NonZeroU32 {
NonZeroU32::new(60).expect("60 != 0")
}
const fn default_max_user_send_burst_size() -> NonZeroU32 {
NonZeroU32::new(10).expect("10 != 0")
}
}
+2 -1
View File
@@ -20,7 +20,8 @@ pub struct OutgoingBeforeQueueHandler {
impl OutgoingBeforeQueueHandler {
pub fn new(config: Config) -> Self {
let quota = Quota::per_minute(config.max_user_send_per_minute);
let quota = Quota::per_minute(config.max_user_send_per_minute)
.allow_burst(config.max_user_send_burst_size);
Self {
config: Arc::new(config),
send_rate_limiter: RateLimiter::keyed(quota),