log conn latency distribution

This commit is contained in:
Youngjoon Lee 2025-02-03 22:18:54 +09:00
parent 0a34168bb0
commit 7400ffa8c2
No known key found for this signature in database
GPG Key ID: D94003D91DE12141
3 changed files with 71 additions and 3 deletions

View File

@ -85,13 +85,26 @@ impl SimulationApp {
&mut rng,
&settings.simulation_settings.network_settings,
);
log!(
"Regions",
regions
.iter()
.map(|(region, node_ids)| (region, node_ids.len()))
.collect::<HashMap<_, _>>()
);
log!("NumRegions", regions.len());
let behaviours = create_behaviours(&settings.simulation_settings.network_settings);
let regions_data = RegionsData::new(regions, behaviours);
let network = Arc::new(Mutex::new(Network::<BlendMessage>::new(regions_data, seed)));
let network = Arc::new(Mutex::new(Network::<BlendMessage>::new(
regions_data.clone(),
seed,
)));
let topology = Topology::new(&node_ids, settings.connected_peers_count, &mut rng);
log_topology(&topology);
log_conn_latency_distribution(&topology.conn_latency_distribution(&regions_data));
let nodes: Vec<_> = node_ids
.iter()
@ -261,6 +274,25 @@ struct TopologyLog {
diameter: usize,
}
fn log_conn_latency_distribution(distribution: &HashMap<Duration, usize>) {
log!(
"ConnLatencyDistribution",
ConnLatencyDistributionLog {
num_links: distribution.values().sum(),
distribution: distribution
.iter()
.map(|(latency, count)| (latency.as_millis(), *count))
.collect::<HashMap<_, _>>(),
}
);
}
#[derive(Debug, Serialize, Deserialize)]
struct ConnLatencyDistributionLog {
num_links: usize,
distribution: HashMap<u128, usize>,
}
fn main() -> anyhow::Result<()> {
let app: SimulationApp = SimulationApp::parse();
let maybe_guard = log::config_tracing(app.log_format, &app.log_to, app.with_metrics);

View File

@ -1,6 +1,12 @@
use std::collections::{HashMap, HashSet};
use std::{
collections::{HashMap, HashSet},
time::Duration,
};
use netrunner::node::{NodeId, NodeIdExt};
use netrunner::{
network::regions::RegionsData,
node::{NodeId, NodeIdExt},
};
use rand::{seq::SliceRandom, RngCore};
#[derive(Clone)]
@ -121,6 +127,28 @@ impl Topology {
hop_count
}
pub fn conn_latency_distribution(
&self,
regions_data: &RegionsData,
) -> HashMap<Duration, usize> {
// Initialize a distribution
let distribution = regions_data
.region_network_behaviour
.values()
.map(|behaviour| (behaviour.delay(), 0))
.collect();
// Populate the distribution
self.0.iter().fold(distribution, |mut acc, (node, peers)| {
let region_a = regions_data.node_region(*node);
peers.iter().for_each(|peer| {
let region_b = regions_data.node_region(*peer);
let behaviour = regions_data.network_behaviour_between_regions(region_a, region_b);
acc.entry(behaviour.delay()).and_modify(|count| *count += 1);
});
acc
})
}
pub fn get(&self, node: &NodeId) -> Option<&HashSet<NodeId>> {
self.0.get(node)
}

View File

@ -121,6 +121,14 @@ impl RegionsData {
pub fn network_behaviour(&self, node_a: NodeId, node_b: NodeId) -> &NetworkBehaviour {
let region_a = self.node_region[&node_a];
let region_b = self.node_region[&node_b];
self.network_behaviour_between_regions(region_a, region_b)
}
pub fn network_behaviour_between_regions(
&self,
region_a: Region,
region_b: Region,
) -> &NetworkBehaviour {
let k = NetworkBehaviourKey::new(region_a, region_b);
let k_rev = NetworkBehaviourKey::new(region_b, region_a);
self.region_network_behaviour