mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-05-06 08:02:18 +00:00
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 <mail@max-inden.de>
This commit is contained in:
parent
c1551d71b6
commit
73dbde1519
@ -198,25 +198,22 @@ async fn custom(server_address: Multiaddr, params: RunParams) -> Result<()> {
|
|||||||
info!("start benchmark: custom");
|
info!("start benchmark: custom");
|
||||||
let mut swarm = swarm().await?;
|
let mut swarm = swarm().await?;
|
||||||
|
|
||||||
let (server_peer_id, connection_established) =
|
let start = Instant::now();
|
||||||
connect(&mut swarm, server_address.clone()).await?;
|
|
||||||
|
|
||||||
let RunDuration { upload, download } = perf(&mut swarm, server_peer_id, params).await?;
|
let server_peer_id = connect(&mut swarm, server_address.clone()).await?;
|
||||||
|
|
||||||
|
perf(&mut swarm, server_peer_id, params).await?;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
struct CustomResult {
|
struct CustomResult {
|
||||||
connection_established_seconds: f64,
|
latency: f64,
|
||||||
upload_seconds: f64,
|
|
||||||
download_seconds: f64,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
"{}",
|
"{}",
|
||||||
serde_json::to_string(&CustomResult {
|
serde_json::to_string(&CustomResult {
|
||||||
connection_established_seconds: connection_established.as_secs_f64(),
|
latency: start.elapsed().as_secs_f64(),
|
||||||
upload_seconds: upload.as_secs_f64(),
|
|
||||||
download_seconds: download.as_secs_f64(),
|
|
||||||
})
|
})
|
||||||
.unwrap()
|
.unwrap()
|
||||||
);
|
);
|
||||||
@ -228,7 +225,7 @@ async fn latency(server_address: Multiaddr) -> Result<()> {
|
|||||||
info!("start benchmark: round-trip-time latency");
|
info!("start benchmark: round-trip-time latency");
|
||||||
let mut swarm = swarm().await?;
|
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 mut rounds = 0;
|
||||||
let start = Instant::now();
|
let start = Instant::now();
|
||||||
@ -275,7 +272,7 @@ async fn throughput(server_address: Multiaddr) -> Result<()> {
|
|||||||
info!("start benchmark: single connection single channel throughput");
|
info!("start benchmark: single connection single channel throughput");
|
||||||
let mut swarm = swarm().await?;
|
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 {
|
let params = RunParams {
|
||||||
to_send: 10 * 1024 * 1024,
|
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");
|
info!("start benchmark: single connection parallel requests per second");
|
||||||
let mut swarm = swarm().await?;
|
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 num = 1_000;
|
||||||
let to_send = 1;
|
let to_send = 1;
|
||||||
@ -356,7 +353,7 @@ async fn sequential_connections_per_second(server_address: Multiaddr) -> Result<
|
|||||||
|
|
||||||
let start = Instant::now();
|
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());
|
latency_connection_establishment.push(start.elapsed().as_secs_f64());
|
||||||
|
|
||||||
@ -427,7 +424,7 @@ async fn swarm<B: NetworkBehaviour + Default>() -> Result<Swarm<B>> {
|
|||||||
async fn connect(
|
async fn connect(
|
||||||
swarm: &mut Swarm<libp2p_perf::client::Behaviour>,
|
swarm: &mut Swarm<libp2p_perf::client::Behaviour>,
|
||||||
server_address: Multiaddr,
|
server_address: Multiaddr,
|
||||||
) -> Result<(PeerId, Duration)> {
|
) -> Result<PeerId> {
|
||||||
let start = Instant::now();
|
let start = Instant::now();
|
||||||
swarm.dial(server_address.clone()).unwrap();
|
swarm.dial(server_address.clone()).unwrap();
|
||||||
|
|
||||||
@ -446,7 +443,7 @@ async fn connect(
|
|||||||
|
|
||||||
info!("established connection in {duration_seconds:.4} s");
|
info!("established connection in {duration_seconds:.4} s");
|
||||||
|
|
||||||
Ok((server_peer_id, duration))
|
Ok(server_peer_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn perf(
|
async fn perf(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user