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 mechanism when buffer is full #4014

Closed
wants to merge 7 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
- Remove the OTEL spans endpoint in favor of Envelopes. ([#3973](https://github.com/getsentry/relay/pull/3973))
- Remove the `generate-schema` tool. Relay no longer exposes JSON schema for the event protocol. Consult the Rust type documentation of the `relay-event-schema` crate instead. ([#3974](https://github.com/getsentry/relay/pull/3974))
- Allow creation of `SqliteEnvelopeBuffer` from config, and load existing stacks from db on startup. ([#3967](https://github.com/getsentry/relay/pull/3967))
- Implement eviction policy when the `EnvelopeBuffer` doesn't have enough capacity. ([#4014](https://github.com/getsentry/relay/pull/4014))

## 24.8.0

Expand Down
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
3 changes: 3 additions & 0 deletions relay-server/benches/benches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,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(),
true,
Expand Down Expand Up @@ -138,6 +139,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(),
true,
Expand Down Expand Up @@ -179,6 +181,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(),
true,
Expand Down
Loading
Loading