Skip to content

Commit 7655467

Browse files
authored
Refactor for batching wait: (#1843)
- start exponential growth from the first advance (vs second previously) - improve some edge cases behavior
1 parent 0d68785 commit 7655467

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

io/zenoh-transport/src/common/pipeline.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,26 @@ impl WaitTime {
167167
}
168168

169169
fn advance(&mut self, instant: &mut Instant) {
170+
// grow wait_time exponentially
171+
self.wait_time = self.wait_time.saturating_mul(2);
172+
173+
// check for waiting limits
170174
match &mut self.max_wait_time {
175+
// if we have reached the waiting limit, we do not increase wait instant
176+
Some(max_wait_time) if *max_wait_time == Duration::ZERO => {
177+
tracing::trace!("Backoff increase limit reached")
178+
}
179+
// if the leftover of waiting time is less than next iteration, we select leftover
180+
Some(max_wait_time) if *max_wait_time <= self.wait_time => {
181+
*instant += *max_wait_time;
182+
*max_wait_time = Duration::ZERO;
183+
}
184+
// if the leftover of waiting time is bigger than next iteration, select next iteration
171185
Some(max_wait_time) => {
172-
if let Some(new_max_wait_time) = max_wait_time.checked_sub(self.wait_time) {
173-
*instant += self.wait_time;
174-
*max_wait_time = new_max_wait_time;
175-
self.wait_time *= 2;
176-
}
186+
*instant += self.wait_time;
187+
*max_wait_time -= self.wait_time;
177188
}
189+
// just select next iteration without checking the upper limit
178190
None => {
179191
*instant += self.wait_time;
180192
}

0 commit comments

Comments
 (0)