mirror of
https://github.com/kristoferssolo/tls-pq-bench.git
synced 2026-03-22 00:36:21 +00:00
feat(runner): separate TLS and TCP handshake latency
This commit is contained in:
@@ -29,10 +29,12 @@ pub struct BenchRecord {
|
|||||||
pub mode: KeyExchangeMode,
|
pub mode: KeyExchangeMode,
|
||||||
/// Payload size in bytes
|
/// Payload size in bytes
|
||||||
pub payload_bytes: u64,
|
pub payload_bytes: u64,
|
||||||
|
/// TCP connection latency in nanoseconds
|
||||||
|
pub tcp_ns: u128,
|
||||||
/// Handshake latency in nanoseconds
|
/// Handshake latency in nanoseconds
|
||||||
pub handshake_ns: u64,
|
pub handshake_ns: u128,
|
||||||
/// Time-to-last-byte in nanoseconds (from connection start)
|
/// Time-to-last-byte in nanoseconds (from connection start)
|
||||||
pub ttlb_ns: u64,
|
pub ttlb_ns: u128,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BenchRecord {
|
impl BenchRecord {
|
||||||
@@ -56,10 +58,9 @@ impl fmt::Display for BenchRecord {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use super::*;
|
||||||
use claims::{assert_err, assert_ok};
|
use claims::{assert_err, assert_ok};
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
|
|
||||||
use super::*;
|
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -68,6 +69,7 @@ mod tests {
|
|||||||
iteration: 0,
|
iteration: 0,
|
||||||
mode: KeyExchangeMode::X25519,
|
mode: KeyExchangeMode::X25519,
|
||||||
payload_bytes: 1024,
|
payload_bytes: 1024,
|
||||||
|
tcp_ns: 500_000,
|
||||||
handshake_ns: 1_000_000,
|
handshake_ns: 1_000_000,
|
||||||
ttlb_ns: 2_000_000,
|
ttlb_ns: 2_000_000,
|
||||||
};
|
};
|
||||||
@@ -83,6 +85,7 @@ mod tests {
|
|||||||
iteration: 42,
|
iteration: 42,
|
||||||
mode: KeyExchangeMode::X25519Mlkem768,
|
mode: KeyExchangeMode::X25519Mlkem768,
|
||||||
payload_bytes: 4096,
|
payload_bytes: 4096,
|
||||||
|
tcp_ns: 1_000_000,
|
||||||
handshake_ns: 5_000_000,
|
handshake_ns: 5_000_000,
|
||||||
ttlb_ns: 10_000_000,
|
ttlb_ns: 10_000_000,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -42,8 +42,9 @@ use uuid::Uuid;
|
|||||||
|
|
||||||
/// Result of a single benchmark iteration.
|
/// Result of a single benchmark iteration.
|
||||||
struct IterationResult {
|
struct IterationResult {
|
||||||
handshake_ns: u64,
|
tcp: u128,
|
||||||
ttlb_ns: u64,
|
handshake: u128,
|
||||||
|
ttlb: u128,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Certificate verifier that accepts any certificate.
|
/// Certificate verifier that accepts any certificate.
|
||||||
@@ -119,28 +120,31 @@ fn build_tls_config(mode: KeyExchangeMode) -> miette::Result<ClientConfig> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Run a single benchmark iteration over TLS.
|
/// Run a single benchmark iteration over TLS.
|
||||||
#[allow(clippy::cast_possible_truncation)] // nanoseconds won't overflow u64 for reasonable durations
|
|
||||||
async fn run_iteration(
|
async fn run_iteration(
|
||||||
server: SocketAddr,
|
server: SocketAddr,
|
||||||
payload_bytes: u32,
|
payload_bytes: u32,
|
||||||
tls_connector: &TlsConnector,
|
tls_connector: &TlsConnector,
|
||||||
server_name: &ServerName<'static>,
|
server_name: &ServerName<'static>,
|
||||||
) -> miette::Result<IterationResult> {
|
) -> miette::Result<IterationResult> {
|
||||||
let start = Instant::now();
|
let tcp_start = Instant::now();
|
||||||
|
|
||||||
let stream = TcpStream::connect(server)
|
let stream = TcpStream::connect(server)
|
||||||
.await
|
.await
|
||||||
.into_diagnostic()
|
.into_diagnostic()
|
||||||
.context("TCP connection failed")?;
|
.context("TCP connection failed")?;
|
||||||
|
|
||||||
|
let tcp_ns = tcp_start.elapsed().as_nanos();
|
||||||
|
|
||||||
|
let hs_start = Instant::now();
|
||||||
let mut tls_stream = tls_connector
|
let mut tls_stream = tls_connector
|
||||||
.connect(server_name.clone(), stream)
|
.connect(server_name.clone(), stream)
|
||||||
.await
|
.await
|
||||||
.into_diagnostic()
|
.into_diagnostic()
|
||||||
.context("TLS handshake failed")?;
|
.context("TLS handshake failed")?;
|
||||||
|
|
||||||
let handshake_ns = start.elapsed().as_nanos() as u64;
|
let handshake_ns = hs_start.elapsed().as_nanos();
|
||||||
|
|
||||||
|
let ttlb_start = Instant::now();
|
||||||
write_request(&mut tls_stream, u64::from(payload_bytes))
|
write_request(&mut tls_stream, u64::from(payload_bytes))
|
||||||
.await
|
.await
|
||||||
.into_diagnostic()
|
.into_diagnostic()
|
||||||
@@ -151,11 +155,12 @@ async fn run_iteration(
|
|||||||
.into_diagnostic()
|
.into_diagnostic()
|
||||||
.context("read payload failed")?;
|
.context("read payload failed")?;
|
||||||
|
|
||||||
let ttlb_ns = start.elapsed().as_nanos() as u64;
|
let ttlb_ns = tcp_ns + handshake_ns + ttlb_start.elapsed().as_nanos();
|
||||||
|
|
||||||
Ok(IterationResult {
|
Ok(IterationResult {
|
||||||
handshake_ns,
|
tcp: tcp_ns,
|
||||||
ttlb_ns,
|
handshake: handshake_ns,
|
||||||
|
ttlb: ttlb_ns,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -259,8 +264,9 @@ fn spawn_single_iteration(
|
|||||||
iteration: u64::from(i),
|
iteration: u64::from(i),
|
||||||
mode,
|
mode,
|
||||||
payload_bytes: u64::from(payload_bytes),
|
payload_bytes: u64::from(payload_bytes),
|
||||||
handshake_ns: result.handshake_ns,
|
tcp_ns: result.tcp,
|
||||||
ttlb_ns: result.ttlb_ns,
|
handshake_ns: result.handshake,
|
||||||
|
ttlb_ns: result.ttlb,
|
||||||
};
|
};
|
||||||
|
|
||||||
(result, Some(record))
|
(result, Some(record))
|
||||||
|
|||||||
Reference in New Issue
Block a user