Skip to content

Commit

Permalink
fix(buffer): Optimistically initialize stacks as ready
Browse files Browse the repository at this point in the history
  • Loading branch information
jjbayer committed Sep 19, 2024
1 parent 8dc1608 commit 2cf2aed
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 6 additions & 4 deletions relay-server/src/services/buffer/envelope_buffer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ where
},
Priority {
readiness,
next_project_fetch: next_peek,
next_project_fetch,
..
},
)) = self.priority_queue.peek_mut()
Expand All @@ -305,7 +305,7 @@ where
Ok(match (stack.peek().await?, ready) {
(None, _) => Peek::Empty,
(Some(envelope), true) => Peek::Ready(envelope),
(Some(envelope), false) => Peek::NotReady(*stack_key, *next_peek, envelope),
(Some(envelope), false) => Peek::NotReady(*stack_key, *next_project_fetch, envelope),
})
}

Expand Down Expand Up @@ -607,9 +607,11 @@ struct Readiness {

impl Readiness {
fn new() -> Self {
// Optimistically set ready state to true.
// The large majority of stack creations are re-creations after a stack was emptied.
Self {
own_project_ready: false,
sampling_project_ready: false,
own_project_ready: true,
sampling_project_ready: true,
}
}

Expand Down
4 changes: 2 additions & 2 deletions relay-server/src/services/buffer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ impl EnvelopeBufferService {
self.services.project_cache.send(DequeuedEnvelope(envelope));
self.sleep = Duration::ZERO; // try next pop immediately
}
Peek::NotReady(stack_key, next_peek, envelope) => {
Peek::NotReady(stack_key, next_project_fetch, envelope) => {
relay_log::trace!("EnvelopeBufferService: project(s) of envelope not ready");
relay_statsd::metric!(
counter(RelayCounters::BufferTryPop) += 1,
Expand All @@ -247,7 +247,7 @@ impl EnvelopeBufferService {
// We want to fetch the configs again, only if some time passed between the last
// peek of this not ready project key pair and the current peek. This is done to
// avoid flooding the project cache with `UpdateProject` messages.
if Instant::now() >= next_peek {
if Instant::now() >= next_project_fetch {
relay_log::trace!("EnvelopeBufferService: requesting project(s) update");
let project_key = envelope.meta().public_key();
self.services.project_cache.send(UpdateProject(project_key));
Expand Down

0 comments on commit 2cf2aed

Please sign in to comment.