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 EnvelopeStack based on SQLite #3855

Merged
merged 24 commits into from
Jul 26, 2024

Conversation

iambriccardo
Copy link
Member

@iambriccardo iambriccardo commented Jul 23, 2024

This PR adds the SQLite implementation of the EnvelopeStack trait. The implementation works in the following way:

  • It keeps a buffer of envelopes in memory, which comprises a stack of arrays, each with a fixed size.
  • The buffer is always filled from the top and flushed to disk only when the size surpasses a certain threshold.
  • When reading, if the buffer is empty, a load from the disk will be attempted.

The idea of the implementation is to allow an in-memory data structure to always serve the most recent envelope and only go to disk when really necessary. So, during low load, it could easily be that the memory buffer is only used and never spilled to disk (assuming thresholds are defined correctly).

It's important to note that we are trading off durability for speed with this design.

Closes: #3855

@iambriccardo iambriccardo marked this pull request as ready for review July 25, 2024 13:38
@iambriccardo iambriccardo requested a review from a team as a code owner July 25, 2024 13:38
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.

Looks good, I think we can merge this into master soon, and then decide on final interfaces (sync vs async etc.) once I merge it with my work.

relay-server/src/services/spooler/envelope_stack/sqlite.rs Outdated Show resolved Hide resolved
relay-server/src/services/spooler/envelope_stack/sqlite.rs Outdated Show resolved Hide resolved
relay-server/src/services/spooler/envelope_stack/sqlite.rs Outdated Show resolved Hide resolved
relay-server/src/services/spooler/envelope_stack/sqlite.rs Outdated Show resolved Hide resolved
relay-server/src/services/spooler/envelope_stack/sqlite.rs Outdated Show resolved Hide resolved
}

if let Some(batch) = self.batches_buffer.front_mut() {
batch.push(envelope);
Copy link
Member

Choose a reason for hiding this comment

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

I'm a bit confused about pushing batches to the front but individual elements to the back. Can we sort both the batches_buffer and the individual batches left-to-right, i.e. push to the back in both cases?

iambriccardo and others added 3 commits July 26, 2024 08:18
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.

As discussed, push front vs push back.

relay-server/src/services/spooler/envelope_stack/sqlite.rs Outdated Show resolved Hide resolved
relay-server/benches/benches.rs Show resolved Hide resolved
@iambriccardo iambriccardo merged commit e56c664 into master Jul 26, 2024
24 checks passed
@iambriccardo iambriccardo deleted the riccardo/feat/envelope-stack branch July 26, 2024 08:50
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.

2 participants