From 69bd90efe5530455c77404609ba6c242fecc719e Mon Sep 17 00:00:00 2001 From: Max Inden Date: Fri, 23 Jun 2023 19:51:16 +0900 Subject: [PATCH 1/2] refactor(perf): expose single latency measurement Instead of exposing the time to establish a connection, the time to upload the bytes and the time to download the bytes, expose a single time including all three only. The rational here is, that differentiation of the three is flawed. E.g. when does one stop the upload timer and start the download timer? When the last byte is sent? When the last byte is flushed? When the first byte is received? --- protocols/perf/src/bin/perf.rs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/protocols/perf/src/bin/perf.rs b/protocols/perf/src/bin/perf.rs index 83ab7fda61c..ad710e1e39e 100644 --- a/protocols/perf/src/bin/perf.rs +++ b/protocols/perf/src/bin/perf.rs @@ -198,25 +198,22 @@ async fn custom(server_address: Multiaddr, params: RunParams) -> Result<()> { info!("start benchmark: custom"); let mut swarm = swarm().await?; - let (server_peer_id, connection_established) = - connect(&mut swarm, server_address.clone()).await?; + let start = Instant::now(); + + let (server_peer_id, _) = connect(&mut swarm, server_address.clone()).await?; - let RunDuration { upload, download } = perf(&mut swarm, server_peer_id, params).await?; + perf(&mut swarm, server_peer_id, params).await?; #[derive(Serialize, Deserialize)] #[serde(rename_all = "camelCase")] struct CustomResult { - connection_established_seconds: f64, - upload_seconds: f64, - download_seconds: f64, + latency: f64, } println!( "{}", serde_json::to_string(&CustomResult { - connection_established_seconds: connection_established.as_secs_f64(), - upload_seconds: upload.as_secs_f64(), - download_seconds: download.as_secs_f64(), + latency: start.elapsed().as_secs_f64(), }) .unwrap() ); From ec8f513046e1eac6ab8a6872e755f1a920195270 Mon Sep 17 00:00:00 2001 From: Max Inden Date: Mon, 26 Jun 2023 12:09:37 +0900 Subject: [PATCH 2/2] fix(bin/perf): don't return connection establishment latency --- protocols/perf/src/bin/perf.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/protocols/perf/src/bin/perf.rs b/protocols/perf/src/bin/perf.rs index ad710e1e39e..b6b090608f5 100644 --- a/protocols/perf/src/bin/perf.rs +++ b/protocols/perf/src/bin/perf.rs @@ -200,7 +200,7 @@ async fn custom(server_address: Multiaddr, params: RunParams) -> Result<()> { let start = Instant::now(); - let (server_peer_id, _) = connect(&mut swarm, server_address.clone()).await?; + let server_peer_id = connect(&mut swarm, server_address.clone()).await?; perf(&mut swarm, server_peer_id, params).await?; @@ -225,7 +225,7 @@ async fn latency(server_address: Multiaddr) -> Result<()> { info!("start benchmark: round-trip-time latency"); let mut swarm = swarm().await?; - let (server_peer_id, _) = connect(&mut swarm, server_address.clone()).await?; + let server_peer_id = connect(&mut swarm, server_address.clone()).await?; let mut rounds = 0; let start = Instant::now(); @@ -272,7 +272,7 @@ async fn throughput(server_address: Multiaddr) -> Result<()> { info!("start benchmark: single connection single channel throughput"); let mut swarm = swarm().await?; - let (server_peer_id, _) = connect(&mut swarm, server_address.clone()).await?; + let server_peer_id = connect(&mut swarm, server_address.clone()).await?; let params = RunParams { to_send: 10 * 1024 * 1024, @@ -288,7 +288,7 @@ async fn requests_per_second(server_address: Multiaddr) -> Result<()> { info!("start benchmark: single connection parallel requests per second"); let mut swarm = swarm().await?; - let (server_peer_id, _) = connect(&mut swarm, server_address.clone()).await?; + let server_peer_id = connect(&mut swarm, server_address.clone()).await?; let num = 1_000; let to_send = 1; @@ -353,7 +353,7 @@ async fn sequential_connections_per_second(server_address: Multiaddr) -> Result< let start = Instant::now(); - let (server_peer_id, _) = connect(&mut swarm, server_address.clone()).await?; + let server_peer_id = connect(&mut swarm, server_address.clone()).await?; latency_connection_establishment.push(start.elapsed().as_secs_f64()); @@ -424,7 +424,7 @@ async fn swarm() -> Result> { async fn connect( swarm: &mut Swarm, server_address: Multiaddr, -) -> Result<(PeerId, Duration)> { +) -> Result { let start = Instant::now(); swarm.dial(server_address.clone()).unwrap(); @@ -443,7 +443,7 @@ async fn connect( info!("established connection in {duration_seconds:.4} s"); - Ok((server_peer_id, duration)) + Ok(server_peer_id) } async fn perf(