Skip to content

Commit

Permalink
feat(spooler): Implement eviction mechanism when buffer is full
Browse files Browse the repository at this point in the history
  • Loading branch information
iambriccardo committed Sep 7, 2024
1 parent d9c39f5 commit 4bd1766
Show file tree
Hide file tree
Showing 9 changed files with 332 additions and 36 deletions.
29 changes: 29 additions & 0 deletions relay-config/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,7 @@ fn spool_envelopes_stack_max_batches() -> usize {
2
}

/// Default maximum time between receiving the envelope and processing it.
fn spool_envelopes_max_envelope_delay_secs() -> u64 {
24 * 60 * 60
}
Expand All @@ -912,6 +913,16 @@ fn spool_disk_usage_refresh_frequency_ms() -> u64 {
100
}

/// Default percentage of envelope stacks that can be evicted in the buffer.
fn spool_envelopes_evictable_stacks_percentage() -> f32 {
0.1
}

/// Default maximum number of envelopes that can be evicted for each stack.
fn spool_envelopes_max_evictable_envelopes() -> usize {
100
}

/// Persistent buffering configuration for incoming envelopes.
#[derive(Debug, Serialize, Deserialize)]
pub struct EnvelopeSpool {
Expand Down Expand Up @@ -955,6 +966,12 @@ pub struct EnvelopeSpool {
/// internal page stats.
#[serde(default = "spool_disk_usage_refresh_frequency_ms")]
disk_usage_refresh_frequency_ms: u64,
/// Percentage of envelope stacks that can be evicted in the buffer.
#[serde(default = "spool_envelopes_evictable_stacks_percentage")]
evictable_stacks_percentage: f32,
/// Maximum number of envelopes that can be evicted for each stack.
#[serde(default = "spool_envelopes_max_evictable_envelopes")]
max_evictable_envelopes: usize,
/// Version of the spooler.
#[serde(default)]
version: EnvelopeSpoolVersion,
Expand Down Expand Up @@ -991,6 +1008,8 @@ impl Default for EnvelopeSpool {
max_batches: spool_envelopes_stack_max_batches(),
max_envelope_delay_secs: spool_envelopes_max_envelope_delay_secs(),
disk_usage_refresh_frequency_ms: spool_disk_usage_refresh_frequency_ms(),
evictable_stacks_percentage: spool_envelopes_evictable_stacks_percentage(),
max_evictable_envelopes: spool_envelopes_max_evictable_envelopes(),
version: EnvelopeSpoolVersion::default(),
}
}
Expand Down Expand Up @@ -2194,6 +2213,16 @@ impl Config {
self.values.spool.envelopes.max_batches
}

/// Maximum number of stacks that can be evicted.
pub fn spool_envelopes_evictable_stacks_percentage(&self) -> f32 {
self.values.spool.envelopes.evictable_stacks_percentage
}

/// Maximum number of envelopes that can be evicted per stack.
pub fn spool_envelopes_stack_max_evictable_envelopes(&self) -> usize {
self.values.spool.envelopes.max_evictable_envelopes
}

/// Returns `true` if version 2 of the spooling mechanism is used.
pub fn spool_v2(&self) -> bool {
matches!(
Expand Down
Loading

0 comments on commit 4bd1766

Please sign in to comment.