Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bench/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ hdrhistogram = { workspace = true }
quinn = { package = "iroh-quinn", path = "../quinn", features = ["ring"] }
rcgen = { workspace = true }
rustls = { workspace = true }
tokio = { workspace = true, features = ["rt"] }
tokio = { workspace = true, features = ["rt", "rt-multi-thread"] }
tracing = { workspace = true }
tracing-subscriber = { workspace = true }

Expand Down
4 changes: 2 additions & 2 deletions bench/src/bin/bulk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn main() {
let cert = CertificateDer::from(cert.cert);

let server_span = tracing::error_span!("server");
let runtime = rt();
let runtime = rt(opt.runtime_type);
let (server_addr, endpoint) = {
let _guard = server_span.enter();
server_endpoint(&runtime, cert.clone(), key.into(), &opt)
Expand All @@ -43,7 +43,7 @@ fn main() {
let cert = cert.clone();
handles.push(std::thread::spawn(move || {
let _guard = tracing::error_span!("client", id).entered();
let runtime = rt();
let runtime = rt(opt.runtime_type);
match runtime.block_on(client(server_addr, cert, opt)) {
Ok(stats) => Ok(stats),
Err(e) => {
Expand Down
42 changes: 40 additions & 2 deletions bench/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,25 @@ pub async fn send_data_on_stream(stream: &mut quinn::SendStream, stream_size: u6
Ok(())
}

pub fn rt() -> Runtime {
Builder::new_current_thread().enable_all().build().unwrap()
pub fn rt(runtime_type: RuntimeType) -> Runtime {
match runtime_type {
RuntimeType::Tokio => {
let counter = std::sync::atomic::AtomicUsize::new(0);
Builder::new_multi_thread()
.thread_name_fn(move || {
format!(
"tokio-runtime-{}",
counter.fetch_add(1, std::sync::atomic::Ordering::Relaxed)
)
})
.enable_all()
.build()
.unwrap()
}
RuntimeType::TokioCurrentThread => {
Builder::new_current_thread().enable_all().build().unwrap()
}
}
}

pub fn transport_config(opt: &Opt) -> quinn::TransportConfig {
Expand Down Expand Up @@ -203,6 +220,27 @@ pub struct Opt {
/// Starting guess for maximum UDP payload size
#[clap(long, default_value = "1200")]
pub initial_mtu: u16,
/// The runtime type to use
#[clap(long, default_value = "tokio")]
pub runtime_type: RuntimeType,
Comment on lines +223 to +225
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In iroh-bench I'm doing some very similar changes, can we align on them? There, I allow configuring the amount of worker threads per endpoint.
IMO this is slightly better than configuring all endpoints to have a multi-threaded runtime, since then you'd be putting multiple full-sized tokio runtimes into a single process.
I've added an admittedly somewhat hacky fallback there where setting --workers-per-ep=0 will use the normal multi-threaded runtime.

}

#[derive(Debug, Clone, Copy)]
pub enum RuntimeType {
Tokio,
TokioCurrentThread,
}

impl FromStr for RuntimeType {
type Err = anyhow::Error;

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.to_lowercase().as_str() {
"tokio" => Ok(RuntimeType::Tokio),
"tokio-current-thread" => Ok(RuntimeType::TokioCurrentThread),
_ => Err(anyhow::anyhow!("Unknown runtime type {}", s)),
}
}
}

fn parse_byte_size(s: &str) -> Result<u64, ParseIntError> {
Expand Down
Loading