Let healthy carrier comparisons recover from startup probe loss
The first probe on a newly opened carrier can precede the responder’s private health profile. Keep measuring for up to 30 seconds if the 20-probe window still contains losses or too few samples. A clean link still qualifies after six seconds. The ordinary 60-percent link failure detector continues to count every missed probe. Tested the acquisition, recovery, insufficient data and persistent-loss decisions. The slow TLS and fast QUIC loopback fixture can expose its measurements through the existing test logging switch. Workspace Clippy and formatting passed.
This commit is contained in:
1 parent
15a4e45710
commit
219bd018db
3 files changed
+41
-18
No files matched your search
@@ -9,7 +9,9 @@ pub(super) const PROTOCOL: &str = "link-choice";
|
|||||||
const RETRY: Duration = Duration::from_secs(3);
|
const RETRY: Duration = Duration::from_secs(3);
|
||||||
const NEXT_TRIAL: Duration = Duration::from_secs(120);
|
const NEXT_TRIAL: Duration = Duration::from_secs(120);
|
||||||
const MIN_WINDOW: Duration = Duration::from_secs(6);
|
const MIN_WINDOW: Duration = Duration::from_secs(6);
|
||||||
const MAX_WINDOW: Duration = Duration::from_secs(18);
|
// Allow a full rolling health window to replace probes sent before the
|
||||||
|
// responder installed its profile. Persistent loss still disqualifies a trial.
|
||||||
|
const MAX_WINDOW: Duration = Duration::from_secs(30);
|
||||||
|
|
||||||
pub(super) fn capability() -> PluginCapability {
|
pub(super) fn capability() -> PluginCapability {
|
||||||
PluginCapability {
|
PluginCapability {
|
||||||
@@ -25,12 +27,18 @@ fn supports_choice(caps: &[PluginCapability]) -> bool {
|
|||||||
.any(|c| c.enabled && c.protocol == PROTOCOL && c.version == 1)
|
.any(|c| c.enabled && c.protocol == PROTOCOL && c.version == 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn better(current: &LinkQuality, alternative: &LinkQuality) -> bool {
|
/// None keeps measuring on the alternative while user traffic stays on the incumbent.
|
||||||
|
fn promotion_decision(age: Duration, measured: Option<(LinkQuality, LinkQuality)>) -> Option<bool> {
|
||||||
|
if age < MIN_WINDOW {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
let Some((current, alternative)) = measured.filter(|(current, alternative)| {
|
||||||
|
current.samples >= 5 && alternative.samples >= 5 && alternative.losses == 0
|
||||||
|
}) else {
|
||||||
|
return (age >= MAX_WINDOW).then_some(false);
|
||||||
|
};
|
||||||
let gain = current.rtt.saturating_sub(alternative.rtt);
|
let gain = current.rtt.saturating_sub(alternative.rtt);
|
||||||
current.samples >= 5
|
Some(gain >= (current.rtt / 5).max(Duration::from_millis(5)))
|
||||||
&& alternative.samples >= 5
|
|
||||||
&& alternative.losses == 0
|
|
||||||
&& gain >= (current.rtt / 5).max(Duration::from_millis(5))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Fixed-size identifiers from the two privately negotiated health profiles.
|
/// Fixed-size identifiers from the two privately negotiated health profiles.
|
||||||
@@ -207,17 +215,11 @@ impl Runtime {
|
|||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
let age = now.duration_since(trial.started);
|
let age = now.duration_since(trial.started);
|
||||||
if age < MIN_WINDOW {
|
let measured = current.quality().zip(candidate.quality());
|
||||||
|
let Some(promote) = promotion_decision(age, measured) else {
|
||||||
return;
|
return;
|
||||||
}
|
};
|
||||||
let measured = current
|
tracing::debug!(peer = %peer.fmt_short(), incumbent = %other, candidate = %trial.protocol, ?measured, promote, "compared data carriers");
|
||||||
.quality()
|
|
||||||
.zip(candidate.quality())
|
|
||||||
.filter(|(a, b)| a.samples >= 5 && b.samples >= 5);
|
|
||||||
if measured.is_none() && age < MAX_WINDOW {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let promote = measured.is_some_and(|(a, b)| better(&a, &b));
|
|
||||||
let (winner, loser) = if promote {
|
let (winner, loser) = if promote {
|
||||||
(candidate, current)
|
(candidate, current)
|
||||||
} else {
|
} else {
|
||||||
@@ -327,8 +329,25 @@ mod tests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn a_loss_during_profile_installation_can_age_out_before_deciding() {
|
||||||
|
let observed =
|
||||||
|
|samples, losses| Some((measurement(200, 20, 0), measurement(30, samples, losses)));
|
||||||
|
assert_eq!(promotion_decision(MIN_WINDOW, observed(5, 1)), None);
|
||||||
|
assert_eq!(
|
||||||
|
promotion_decision(Duration::from_secs(24), observed(20, 0)),
|
||||||
|
Some(true)
|
||||||
|
);
|
||||||
|
assert_eq!(promotion_decision(MAX_WINDOW, observed(18, 2)), Some(false));
|
||||||
|
assert_eq!(promotion_decision(MAX_WINDOW, observed(4, 0)), Some(false));
|
||||||
|
assert_eq!(promotion_decision(MIN_WINDOW / 2, observed(5, 0)), None);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn promote_only_a_sampled_reliable_and_materially_faster_path() {
|
fn promote_only_a_sampled_reliable_and_materially_faster_path() {
|
||||||
|
let better = |current: &LinkQuality, candidate: &LinkQuality| {
|
||||||
|
promotion_decision(MAX_WINDOW, Some((*current, *candidate))) == Some(true)
|
||||||
|
};
|
||||||
let current = measurement(350, 20, 1);
|
let current = measurement(350, 20, 1);
|
||||||
assert!(better(¤t, &measurement(60, 6, 0)));
|
assert!(better(¤t, &measurement(60, 6, 0)));
|
||||||
assert!(!better(¤t, &measurement(60, 1, 0)));
|
assert!(!better(¤t, &measurement(60, 1, 0)));
|
||||||
|
|||||||
@@ -75,6 +75,7 @@ impl Node {
|
|||||||
ports: Arc<std::sync::Mutex<Vec<(EndpointId, u16)>>>,
|
ports: Arc<std::sync::Mutex<Vec<(EndpointId, u16)>>>,
|
||||||
register_transport: bool,
|
register_transport: bool,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
|
tsunagi::testing::init_tracing();
|
||||||
let root = TempDir::new().unwrap();
|
let root = TempDir::new().unwrap();
|
||||||
let identity = tsunagi::storage::StateStore::open(
|
let identity = tsunagi::storage::StateStore::open(
|
||||||
tsunagi::StoragePaths::under(root.path()).state_db(),
|
tsunagi::StoragePaths::under(root.path()).state_db(),
|
||||||
|
|||||||
+5
-2
@@ -111,8 +111,11 @@ a trial. A failed active link still triggers immediate fallback.
|
|||||||
The measurements use authenticated round trips over the data carrier. After
|
The measurements use authenticated round trips over the data carrier. After
|
||||||
at least six seconds and five successful probes on each link, the alternative
|
at least six seconds and five successful probes on each link, the alternative
|
||||||
must have zero observed loss in its window and a median RTT improvement of
|
must have zero observed loss in its window and a median RTT improvement of
|
||||||
at least 20% and 5 ms. Otherwise traffic stays on the incumbent. The agents
|
at least 20% and 5 ms. If early probes are lost while the responder installs
|
||||||
coordinate retirement over their authenticated control session. An older peer
|
its probe profile, the dialler keeps sampling for up to 30 seconds so those
|
||||||
|
losses can leave the 20-probe window. The incumbent stays selected if the
|
||||||
|
alternative fails to qualify. The agents coordinate retirement over their
|
||||||
|
authenticated control session. An older peer
|
||||||
continues using the configured order and failure recovery. One enabled carrier
|
continues using the configured order and failure recovery. One enabled carrier
|
||||||
restricts the pair to that carrier.
|
restricts the pair to that carrier.
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user