diff options
Diffstat (limited to 'src/simtest')
| -rw-r--r-- | src/simtest/bench.rs | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/src/simtest/bench.rs b/src/simtest/bench.rs index 19603d2..40b413d 100644 --- a/src/simtest/bench.rs +++ b/src/simtest/bench.rs @@ -550,14 +550,16 @@ async fn run(seed: u64, scenario: &'static Scenario) -> String { (start, Totals::of(&nodes).await), converged, ); - trees(&mut out, &nodes).await; + trees(&mut out, &nodes, &sim.net).await; } out } /// Every node's own writer's tree (`swarm::tree::own_shape`, `/admin/stats`), as it -/// computes it at the end: the hops its writes take, and the members it leaves out. -async fn trees(out: &mut String, nodes: &[AppState]) { +/// computes it at the end: the hops its writes take, and the members it leaves out; +/// and how long they take by the links' latencies alone, against parents chosen by +/// latency and the fastest paths (`swarm::tree::own_latencies`). +async fn trees(out: &mut String, nodes: &[AppState], net: &crate::transport::sim::SimNet) { let mut shapes = Vec::new(); for node in nodes { shapes.extend(crate::swarm::tree::own_shape(node).await); @@ -586,6 +588,38 @@ async fn trees(out: &mut String, nodes: &[AppState]) { }, off as f64 / count, ); + + // Node IDs to the net's names (each node's alias). + let names: std::collections::HashMap<String, String> = nodes + .iter() + .filter_map(|node| Some((node.local_id().to_owned(), node.alias.clone()?))) + .collect(); + let latency = |from: &str, to: &str| match (names.get(from), names.get(to)) { + (Some(from), Some(to)) => net.mean_delay(from, to).as_secs_f64() * 1000.0, + _ => f64::NAN, + }; + let mut latencies = Vec::new(); + for node in nodes { + latencies.extend(crate::swarm::tree::own_latencies(node, &latency).await); + } + let members: usize = latencies.iter().map(|l| l.members).sum(); + if members == 0 { + return; + } + let mean = |of: fn(&crate::swarm::tree::Latencies) -> f64| { + latencies + .iter() + .map(|l| of(l) * l.members as f64) + .sum::<f64>() + / members as f64 + }; + let _ = writeln!( + out, + " by link latency, to a member: {:.0} ms along own trees; {:.0} ms with parents chosen by latency; {:.0} ms by the fastest paths", + mean(|l| l.tree), + mean(|l| l.by_latency), + mean(|l| l.fastest), + ); } /// The workload's counts (`during`), and the quiet phase's for as long. |
