Skip to content

Commit f09a9f0

Browse files
committed
List the cluster while the lease loop waits to renew
The lease loop listed the cluster after each renewal and only then started the wait for the next one, so a slow listing, up to its timeout, pushed every renewal back by as much. Under load, a slow renewal (its requests sent again) followed by a listing that timed out left about 750 ms of the lease's margin at the divided test timings. * The listing now runs alongside the wait. The next renewal starts once both are done, so the two still never overlap. * After a failed renewal the loop skips the listing, so that a slow one cannot hold up the retry.
1 parent f6ad57d commit f09a9f0

1 file changed

Lines changed: 15 additions & 10 deletions

File tree

‎src/workerd/server/cluster/cluster.rs‎

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -414,22 +414,27 @@ impl Cluster {
414414
}
415415
step = self.lease.borrow_mut().renewed(now_ms(), result);
416416
}
417-
let delay = match step {
417+
let wait = match step {
418418
Step::Fence(reason) => return reason,
419419
Step::Retry(reason) => {
420420
tracing::warn!("renewing the cluster lease failed; retrying: {reason}");
421-
timing.retry_ms
421+
tokio::time::sleep(ms(timing.retry_ms)).await;
422+
continue;
422423
}
423-
Step::Renew => timing.interval_ms,
424+
Step::Renew => tokio::time::sleep(ms(timing.interval_ms)),
424425
};
425426
// A stale listing only delays routing to a new peer: its
426-
// failure is logged, never fatal.
427-
match timeout(ms(timing.list_timeout_ms), self.list_round(&timing)).await {
428-
Ok(Ok(_)) => {}
429-
Ok(Err(e)) => tracing::warn!("listing the cluster failed: {e}"),
430-
Err(_) => tracing::warn!("listing the cluster timed out"),
431-
}
432-
tokio::time::sleep(ms(delay)).await;
427+
// failure is logged, never fatal. It runs during the wait for
428+
// the next renewal, which a slow one delays only past that wait,
429+
// and not after a failed renewal, whose retry it would delay.
430+
let list = async {
431+
match timeout(ms(timing.list_timeout_ms), self.list_round(&timing)).await {
432+
Ok(Ok(_)) => {}
433+
Ok(Err(e)) => tracing::warn!("listing the cluster failed: {e}"),
434+
Err(_) => tracing::warn!("listing the cluster timed out"),
435+
}
436+
};
437+
futures::join!(list, wait);
433438
}
434439
}
435440

0 commit comments

Comments
 (0)