From 73dbde1519f71aa8d76f4c5fa018860ddcd2a8ea Mon Sep 17 00:00:00 2001 From: Max Inden Date: Mon, 26 Jun 2023 05:56:17 +0200 Subject: [PATCH] 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. 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? See https://github.com/libp2p/test-plans/pull/184#pullrequestreview-1482600521 for past discussion. Pull-Request: #4105. Co-Authored-By: Max Inden --- protocols/perf/src/bin/perf.rs | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/protocols/perf/src/bin/perf.rs b/protocols/perf/src/bin/perf.rs index 83ab7fda61c..b6b090608f5 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() ); @@ -228,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(); @@ -275,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, @@ -291,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; @@ -356,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()); @@ -427,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(); @@ -446,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(