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

feat(spooler): Implement eviction algorithm for EnvelopeBuffer #3932

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions relay-config/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -860,10 +860,21 @@ 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
}

/// Default maximum number of stacks that can be evicted.
fn spool_envelopes_max_evictable_stacks() -> usize {
100
}

/// 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 @@ -903,6 +914,12 @@ pub struct EnvelopeSpool {
/// they are dropped. Defaults to 24h.
#[serde(default = "spool_envelopes_max_envelope_delay_secs")]
max_envelope_delay_secs: u64,
/// Maximum number of stacks that can be evicted.
#[serde(default = "spool_envelopes_max_evictable_stacks")]
max_evictable_stacks: usize,
/// 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 @@ -938,6 +955,8 @@ impl Default for EnvelopeSpool {
disk_batch_size: spool_envelopes_stack_disk_batch_size(),
max_batches: spool_envelopes_stack_max_batches(),
max_envelope_delay_secs: spool_envelopes_max_envelope_delay_secs(),
max_evictable_stacks: spool_envelopes_max_evictable_stacks(),
max_evictable_envelopes: spool_envelopes_max_evictable_envelopes(),
version: EnvelopeSpoolVersion::default(),
}
}
Expand Down Expand Up @@ -2149,6 +2168,16 @@ impl Config {
self.values.spool.envelopes.max_batches
}

/// Maximum number of stacks that can be evicted.
pub fn spool_envelopes_stack_max_evictable_stacks(&self) -> usize {
self.values.spool.envelopes.max_evictable_stacks
}

/// 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
3 changes: 3 additions & 0 deletions relay-server/benches/benches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ fn benchmark_sqlite_envelope_stack(c: &mut Criterion) {
envelope_store.clone(),
disk_batch_size,
2,
10,
ProjectKey::parse("e12d836b15bb49d7bbf99e64295d995b").unwrap(),
ProjectKey::parse("e12d836b15bb49d7bbf99e64295d995b").unwrap(),
);
Expand Down Expand Up @@ -135,6 +136,7 @@ fn benchmark_sqlite_envelope_stack(c: &mut Criterion) {
envelope_store.clone(),
disk_batch_size,
2,
10,
ProjectKey::parse("e12d836b15bb49d7bbf99e64295d995b").unwrap(),
ProjectKey::parse("e12d836b15bb49d7bbf99e64295d995b").unwrap(),
);
Expand Down Expand Up @@ -175,6 +177,7 @@ fn benchmark_sqlite_envelope_stack(c: &mut Criterion) {
envelope_store.clone(),
disk_batch_size,
2,
10,
ProjectKey::parse("e12d836b15bb49d7bbf99e64295d995b").unwrap(),
ProjectKey::parse("e12d836b15bb49d7bbf99e64295d995b").unwrap(),
);
Expand Down
Loading
Loading