Skip to content

Commit 147e6bb

Browse files
bench: add ipv6 option and metrics feature
1 parent 1a5c4dd commit 147e6bb

File tree

5 files changed

+33
-19
lines changed

5 files changed

+33
-19
lines changed

iroh/bench/Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ publish = false
88
[dependencies]
99
bytes = "1.7"
1010
hdrhistogram = { version = "7.2", default-features = false }
11-
iroh = { path = ".." }
12-
iroh-metrics = "0.37"
11+
iroh = { path = "..", default-features = false }
12+
iroh-metrics = { version = "0.37", optional = true }
1313
n0-future = "0.3.0"
1414
n0-error = "0.1.0"
1515
quinn = { package = "iroh-quinn", git = "https://github.com/n0-computer/quinn", branch = "main-iroh" }
@@ -28,5 +28,6 @@ tracing-subscriber = { version = "0.3.0", default-features = false, features = [
2828
] }
2929

3030
[features]
31-
default = []
31+
default = ["metrics"]
32+
metrics = ["iroh/metrics", "iroh-metrics"]
3233
local-relay = ["iroh/test-utils"]

iroh/bench/src/bin/bulk.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
#[cfg(feature = "metrics")]
12
use std::collections::BTreeMap;
23

34
use clap::Parser;
45
#[cfg(not(any(target_os = "freebsd", target_os = "openbsd", target_os = "netbsd")))]
56
use iroh_bench::quinn;
67
use iroh_bench::{Commands, Opt, configure_tracing_subscriber, iroh, rt, s2n};
8+
#[cfg(feature = "metrics")]
79
use iroh_metrics::{MetricValue, MetricsGroup};
810
use n0_error::Result;
911

@@ -52,6 +54,7 @@ pub fn run_iroh(opt: Opt) -> Result<()> {
5254
iroh::server_endpoint(&runtime, &relay_url, &opt)
5355
};
5456

57+
#[cfg(feature = "metrics")]
5558
let endpoint_metrics = endpoint.metrics().clone();
5659

5760
let server_thread = std::thread::spawn(move || {
@@ -86,6 +89,7 @@ pub fn run_iroh(opt: Opt) -> Result<()> {
8689
}
8790
}
8891

92+
#[cfg(feature = "metrics")]
8993
if opt.metrics {
9094
// print metrics
9195
println!("\nMetrics:");
@@ -158,6 +162,7 @@ pub fn run_s2n(_opt: s2n::Opt) -> Result<()> {
158162
unimplemented!()
159163
}
160164

165+
#[cfg(feature = "metrics")]
161166
fn collect_and_print(category: &'static str, metrics: &dyn MetricsGroup) {
162167
let mut map = BTreeMap::new();
163168
for item in metrics.iter() {

iroh/bench/src/iroh.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,9 @@ pub fn transport_config(max_streams: usize, initial_mtu: u16) -> TransportConfig
133133
config.max_concurrent_uni_streams(max_streams.try_into().unwrap());
134134
config.initial_mtu(initial_mtu);
135135

136-
// TODO: re-enable when we upgrade quinn version
137-
// let mut acks = quinn::AckFrequencyConfig::default();
138-
// acks.ack_eliciting_threshold(10u32.into());
139-
// config.ack_frequency_config(Some(acks));
136+
let mut acks = quinn::AckFrequencyConfig::default();
137+
acks.ack_eliciting_threshold(10u32.into());
138+
config.ack_frequency_config(Some(acks));
140139

141140
config
142141
}

iroh/bench/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ pub struct Opt {
7474
#[cfg(feature = "local-relay")]
7575
#[clap(long, default_value_t = false)]
7676
pub only_relay: bool,
77+
#[clap(long, default_value_t = false)]
78+
pub use_ipv6: bool,
7779
}
7880

7981
pub enum EndpointSelector {

iroh/bench/src/quinn.rs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use std::{
2-
net::{IpAddr, Ipv4Addr, SocketAddr},
2+
net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr},
33
sync::Arc,
44
time::{Duration, Instant},
55
};
@@ -32,13 +32,15 @@ pub fn server_endpoint(
3232
let mut server_config = quinn::ServerConfig::with_single_cert(cert_chain, key).unwrap();
3333
server_config.transport = Arc::new(transport_config(opt.max_streams, opt.initial_mtu));
3434

35+
let addr = if opt.use_ipv6 {
36+
IpAddr::V6(Ipv6Addr::LOCALHOST)
37+
} else {
38+
IpAddr::V4(Ipv4Addr::LOCALHOST)
39+
};
40+
3541
let endpoint = {
3642
let _guard = rt.enter();
37-
quinn::Endpoint::server(
38-
server_config,
39-
SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), 0),
40-
)
41-
.unwrap()
43+
quinn::Endpoint::server(server_config, SocketAddr::new(addr, 0)).unwrap()
4244
};
4345
let server_addr = endpoint.local_addr().unwrap();
4446
(server_addr, endpoint)
@@ -69,8 +71,13 @@ pub async fn connect_client(
6971
server_cert: CertificateDer<'_>,
7072
opt: Opt,
7173
) -> Result<(::quinn::Endpoint, Connection)> {
72-
let endpoint =
73-
quinn::Endpoint::client(SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), 0)).unwrap();
74+
let addr = if opt.use_ipv6 {
75+
IpAddr::V6(Ipv6Addr::LOCALHOST)
76+
} else {
77+
IpAddr::V4(Ipv4Addr::LOCALHOST)
78+
};
79+
80+
let endpoint = quinn::Endpoint::client(SocketAddr::new(addr, 0)).unwrap();
7481

7582
let mut roots = RootCertStore::empty();
7683
roots.add(server_cert).anyerr()?;
@@ -103,11 +110,11 @@ pub fn transport_config(max_streams: usize, initial_mtu: u16) -> TransportConfig
103110
let mut config = TransportConfig::default();
104111
config.max_concurrent_uni_streams(max_streams.try_into().unwrap());
105112
config.initial_mtu(initial_mtu);
113+
config.max_concurrent_multipath_paths(16);
106114

107-
// TODO: re-enable when we upgrade quinn version
108-
// let mut acks = quinn::AckFrequencyConfig::default();
109-
// acks.ack_eliciting_threshold(10u32.into());
110-
// config.ack_frequency_config(Some(acks));
115+
let mut acks = quinn::AckFrequencyConfig::default();
116+
acks.ack_eliciting_threshold(10u32.into());
117+
config.ack_frequency_config(Some(acks));
111118

112119
config
113120
}

0 commit comments

Comments
 (0)