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): Add ability to partition the buffer into multiple ones #4291

Merged
merged 28 commits into from
Nov 26, 2024

Conversation

iambriccardo
Copy link
Member

@iambriccardo iambriccardo commented Nov 25, 2024

This PR allows the buffer to be partitioned across several partitions. For simplicity, partitioning is achieved at the highest level, meaning that Relay will run x independent partitions of the same EnvelopeBufferService each with its own database file (if the database config is used).

@iambriccardo iambriccardo changed the title Fix feat(spooler): Add ability to shard the buffer into multiple ones Nov 25, 2024
@iambriccardo iambriccardo marked this pull request as ready for review November 26, 2024 09:02
@iambriccardo iambriccardo requested a review from a team as a code owner November 26, 2024 09:02
@iambriccardo iambriccardo changed the title feat(spooler): Add ability to shard the buffer into multiple ones feat(spooler): Add ability to partition the buffer into multiple ones Nov 26, 2024
@iambriccardo iambriccardo requested a review from jjbayer November 26, 2024 09:02
Copy link
Member

@jjbayer jjbayer left a comment

Choose a reason for hiding this comment

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

Nice!

relay-server/src/service.rs Outdated Show resolved Hide resolved
relay-server/src/services/buffer/mod.rs Outdated Show resolved Hide resolved
relay-server/src/services/buffer/mod.rs Outdated Show resolved Hide resolved
relay-server/src/services/buffer/mod.rs Outdated Show resolved Hide resolved

// Keep all the services in one context.
let project_cache_services = legacy::Services {
envelope_buffer: envelope_buffer.as_ref().map(ObservableEnvelopeBuffer::addr),
partitioned_buffer: partitioned_buffer.clone(),
Copy link
Member

Choose a reason for hiding this comment

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

nit: I would still call this field envelope_buffer, the use does not really care whether it partitions internally or not.

relay-config/src/config.rs Outdated Show resolved Hide resolved
relay-server/src/services/health_check.rs Outdated Show resolved Hide resolved
relay-server/src/services/health_check.rs Outdated Show resolved Hide resolved
@@ -356,8 +370,14 @@ impl ServiceState {
}

/// Returns the V2 envelope buffer, if present.
pub fn envelope_buffer(&self) -> Option<&ObservableEnvelopeBuffer> {
self.inner.registry.envelope_buffer.as_ref()
pub fn envelope_buffer(
Copy link
Member

Choose a reason for hiding this comment

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

I would change the interface of PartitionedEnvelopeBuffer to behave roughly like ObservableEnvelopeBuffer behaved before. I.e. give it a send(..) and a has_capacity() method, but not expose internals about partitioning.

Copy link
Member Author

Choose a reason for hiding this comment

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

I thought about this when designing the API, but it conflicted with how we access the buffer in the queue_envelope. I wanted to keep that logic like it is right now.

relay-server/src/services/buffer/mod.rs Outdated Show resolved Hide resolved
@iambriccardo iambriccardo requested a review from jjbayer November 26, 2024 11:17
relay-config/src/config.rs Outdated Show resolved Hide resolved
relay-config/src/config.rs Outdated Show resolved Hide resolved
Comment on lines +119 to +143
let mut envelope_buffers = Vec::with_capacity(partitions.get() as usize);
for partition_id in 0..partitions.get() {
let envelope_buffer = EnvelopeBufferService::new(
partition_id,
config.clone(),
memory_stat.clone(),
global_config_rx.clone(),
Services {
envelopes_tx: envelopes_tx.clone(),
project_cache_handle: project_cache_handle.clone(),
outcome_aggregator: outcome_aggregator.clone(),
test_store: test_store.clone(),
},
)
.map(|b| b.start_in(runner));

if let Some(envelope_buffer) = envelope_buffer {
envelope_buffers.push(envelope_buffer);
}
}

Self {
buffers: Arc::new(envelope_buffers),
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

You can do this with collect, though it's probably a matter of taste which is better.

Suggested change
let mut envelope_buffers = Vec::with_capacity(partitions.get() as usize);
for partition_id in 0..partitions.get() {
let envelope_buffer = EnvelopeBufferService::new(
partition_id,
config.clone(),
memory_stat.clone(),
global_config_rx.clone(),
Services {
envelopes_tx: envelopes_tx.clone(),
project_cache_handle: project_cache_handle.clone(),
outcome_aggregator: outcome_aggregator.clone(),
test_store: test_store.clone(),
},
)
.map(|b| b.start_in(runner));
if let Some(envelope_buffer) = envelope_buffer {
envelope_buffers.push(envelope_buffer);
}
}
Self {
buffers: Arc::new(envelope_buffers),
}
}
let envelope_buffers = (0..partitions.get())
.filter_map(|partition_id| {
EnvelopeBufferService::new(
partition_id,
config.clone(),
memory_stat.clone(),
global_config_rx.clone(),
Services {
envelopes_tx: envelopes_tx.clone(),
project_cache_handle: project_cache_handle.clone(),
outcome_aggregator: outcome_aggregator.clone(),
test_store: test_store.clone(),
},
)
})
.map(|b| b.start_in(runner))
.collect();

This reverts commit d59258b.
@iambriccardo iambriccardo enabled auto-merge (squash) November 26, 2024 13:55
@iambriccardo iambriccardo merged commit 35e9bff into master Nov 26, 2024
23 checks passed
@iambriccardo iambriccardo deleted the riccardo/feat/sharded-buffer branch November 26, 2024 14:04
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.

3 participants