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(