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

improve op propagation limit #4267

Merged
merged 2 commits into from
Jul 24, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,6 @@ impl PropagationThread {
fn prune_propagation_storage(&mut self) {
let mut removed = PreHashSet::default();

// cap cache size
while self.stored_for_propagation.len() > self.config.max_ops_kept_for_propagation {
if let Some((_t, op_ids)) = self.stored_for_propagation.pop_front() {
removed.extend(op_ids);
} else {
break;
}
}

// remove expired
let max_op_prop_time = self.config.max_operations_propagation_time.to_duration();
while let Some((t, _)) = self.stored_for_propagation.front() {
Expand All @@ -123,6 +114,24 @@ impl PropagationThread {
}
}

// Cap cache size
// Note that we directly remove batches of operations, not individual operations
// to favor simplicity and performance over precision.
let mut excess_count = self
.stored_for_propagation
.iter()
.map(|(_, ops)| ops.len())
.sum::<usize>()
.saturating_sub(self.config.max_ops_kept_for_propagation);
while excess_count > 0 {
if let Some((_t, op_ids)) = self.stored_for_propagation.pop_front() {
excess_count = excess_count.saturating_sub(op_ids.len());
removed.extend(op_ids);
} else {
break;
}
}

// remove from storage
self.op_storage.drop_operation_refs(&removed);
}
Expand Down