Skip to content

Commit

Permalink
Notify only if changed
Browse files Browse the repository at this point in the history
  • Loading branch information
jjbayer committed Jul 28, 2024
1 parent 3d21861 commit 29fe242
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion relay-server/src/services/buffer/envelopebuffer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub trait EnvelopeBuffer: std::fmt::Debug + Send {
fn push(&mut self, envelope: Box<Envelope>);
fn peek(&mut self) -> Option<&Envelope>;
fn pop(&mut self) -> Option<Box<Envelope>>;
fn mark_ready(&mut self, project: &ProjectKey, is_ready: bool);
fn mark_ready(&mut self, project: &ProjectKey, is_ready: bool) -> bool;
}

pub fn create(config: &Config) -> Arc<Mutex<dyn EnvelopeBuffer>> {
Expand Down
14 changes: 11 additions & 3 deletions relay-server/src/services/buffer/envelopebuffer/priority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,22 +136,30 @@ impl<S: EnvelopeStack + std::fmt::Debug> EnvelopeBuffer for PriorityEnvelopeBuff
Some(envelope)
}

fn mark_ready(&mut self, project: &ProjectKey, is_ready: bool) {
fn mark_ready(&mut self, project: &ProjectKey, is_ready: bool) -> bool {
relay_log::trace!("PriorityEnvelopeBuffer: mark_ready");
let mut changed = false;
if let Some(stack_keys) = self.own_keys.get(project) {
for stack_key in stack_keys {
self.priority_queue.change_priority_by(stack_key, |stack| {
stack.own_ready = is_ready;
if is_ready != stack.own_ready {
stack.own_ready = is_ready;
changed = true;
}
});
}
}
if let Some(stack_keys) = self.sampling_keys.get(project) {
for stack_key in stack_keys {
self.priority_queue.change_priority_by(stack_key, |stack| {
stack.sampling_ready = is_ready;
if is_ready != stack.sampling_ready {
stack.sampling_ready = is_ready;
changed = true;
}
});
}
}
changed
}
}

Expand Down
12 changes: 8 additions & 4 deletions relay-server/src/services/buffer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ impl EnvelopeBuffer {

pub async fn mark_ready(&self, project_key: &ProjectKey, ready: bool) {
let mut guard = self.backend.lock().await;
guard.mark_ready(project_key, ready);
self.notify();
let changed = guard.mark_ready(project_key, ready);
if changed {
self.notify();
}
}

fn notify(&self) {
Expand Down Expand Up @@ -106,8 +108,10 @@ impl Peek<'_> {
/// Since [`Peek`] already has exclusive access to the buffer, it can mark projects as ready
/// without awaiting the lock.
pub fn mark_ready(&mut self, project_key: &ProjectKey, ready: bool) {
self.notify();
self.guard.mark_ready(project_key, ready);
let changed = self.guard.mark_ready(project_key, ready);
if changed {
self.notify();
}
}

fn notify(&self) {
Expand Down

0 comments on commit 29fe242

Please sign in to comment.