mirror of
https://github.com/logos-blockchain/logos-blockchain-simulations.git
synced 2026-01-07 07:33:13 +00:00
log conn latency distribution
This commit is contained in:
parent
0a34168bb0
commit
7400ffa8c2
@ -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(®ions_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);
|
||||
|
||||
@ -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)
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user