Skip to content

Commit

Permalink
refactor(perf): expose single latency measurement
Browse files Browse the repository at this point in the history
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 libp2p/test-plans#184 (review) for past discussion.

Pull-Request: #4105.


  
Co-Authored-By: Max Inden <mail@max-inden.de>
  • Loading branch information
mxinden authored Jun 26, 2023
1 parent c1551d7 commit 73dbde1
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions protocols/perf/src/bin/perf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
Expand All @@ -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();
Expand Down Expand Up @@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -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());

Expand Down Expand Up @@ -427,7 +424,7 @@ async fn swarm<B: NetworkBehaviour + Default>() -> Result<Swarm<B>> {
async fn connect(
swarm: &mut Swarm<libp2p_perf::client::Behaviour>,
server_address: Multiaddr,
) -> Result<(PeerId, Duration)> {
) -> Result<PeerId> {
let start = Instant::now();
swarm.dial(server_address.clone()).unwrap();

Expand All @@ -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(
Expand Down

0 comments on commit 73dbde1

Please sign in to comment.