Skip to content

Commit

Permalink
fix small bug in backoff update (#1586)
Browse files Browse the repository at this point in the history
* fix small bug in backoff update - use saturating_sub
* additional important optimization for tx
  • Loading branch information
yellowhatter authored Nov 8, 2024
1 parent 3d86ed4 commit da11732
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions io/zenoh-transport/src/common/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ enum Pull {
// Inner structure to keep track and signal backoff operations
#[derive(Clone)]
struct Backoff {
threshold: Duration,
threshold: MicroSeconds,
last_bytes: BatchSize,
atomic: Arc<AtomicBackoff>,
// active: bool,
Expand All @@ -443,7 +443,7 @@ struct Backoff {
impl Backoff {
fn new(threshold: Duration, atomic: Arc<AtomicBackoff>) -> Self {
Self {
threshold,
threshold: threshold.as_micros() as MicroSeconds,
last_bytes: 0,
atomic,
// active: false,
Expand Down Expand Up @@ -486,14 +486,13 @@ impl StageOutIn {
// Verify that we have not been doing backoff for too long
let mut backoff = 0;
if !pull {
let diff = LOCAL_EPOCH.elapsed().as_micros() as MicroSeconds
- self.backoff.atomic.first_write.load(Ordering::Relaxed);
let threshold = self.backoff.threshold.as_micros() as MicroSeconds;
let diff = (LOCAL_EPOCH.elapsed().as_micros() as MicroSeconds)
.saturating_sub(self.backoff.atomic.first_write.load(Ordering::Relaxed));

if diff >= threshold {
if diff >= self.backoff.threshold {
pull = true;
} else {
backoff = threshold - diff;
backoff = self.backoff.threshold - diff;
}
}

Expand Down

0 comments on commit da11732

Please sign in to comment.