Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[network] Add benchmark for transport with TCP_NODELAY set #1653

Closed
wants to merge 1 commit into from
Closed
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
26 changes: 26 additions & 0 deletions network/benches/socket_muxer_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,21 @@ fn bench_tcp_send(b: &mut Bencher, msg_len: &usize, server_addr: Multiaddr) {
bench_client_stream_send(b, *msg_len, &mut runtime, server_addr, client_transport);
}

/// Benchmark the throughput of sending messages of size `msg_len` over tcp to
/// server at multiaddr `server_addr` with TCP_NODELAY set.
fn bench_tcp_send_with_nodelay(b: &mut Bencher, msg_len: &usize, server_addr: Multiaddr) {
let mut runtime = Runtime::new().unwrap();

let client_transport = TcpTransport {
nodelay: Some(true),
..TcpTransport::default()
};

// Benchmark sending some data to the server.
let _client_stream =
bench_client_stream_send(b, *msg_len, &mut runtime, server_addr, client_transport);
}

/// Benchmark the throughput of sending messages of size `msg_len` over tcp with
/// Noise encryption to server at multiaddr `server_addr`.
fn bench_tcp_noise_send(b: &mut Bencher, msg_len: &usize, server_addr: Multiaddr) {
Expand Down Expand Up @@ -348,6 +363,14 @@ fn socket_muxer_bench(c: &mut Criterion) {
TcpTransport::default(),
"/ip4/127.0.0.1/tcp/0".parse().unwrap(),
);
let local_tcp_nodelay_addr = start_stream_server(
&executor,
TcpTransport {
nodelay: Some(true),
..TcpTransport::default()
},
"/ip4/127.0.0.1/tcp/0".parse().unwrap(),
);
let local_tcp_noise_addr = start_stream_server(
&executor,
build_tcp_noise_transport(),
Expand Down Expand Up @@ -394,6 +417,9 @@ fn socket_muxer_bench(c: &mut Criterion) {
})
.with_function("local_tcp+noise+muxer", move |b, msg_len| {
bench_tcp_noise_muxer_send(b, msg_len, local_tcp_noise_muxer_addr.clone())
})
.with_function("local_tcp_nodelay", move |b, msg_len| {
bench_tcp_send_with_nodelay(b, msg_len, local_tcp_nodelay_addr.clone())
});

// optionally enable remote benches if the env variables are set
Expand Down
10 changes: 5 additions & 5 deletions network/netcore/src/transport/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ use tokio::net::tcp::{TcpListener, TcpStream};
#[derive(Debug, Clone, Default)]
pub struct TcpTransport {
/// Size of the recv buffer size to set for opened sockets, or `None` to keep default.
recv_buffer_size: Option<usize>,
pub recv_buffer_size: Option<usize>,
/// Size of the send buffer size to set for opened sockets, or `None` to keep default.
send_buffer_size: Option<usize>,
pub send_buffer_size: Option<usize>,
/// TTL to set for opened sockets, or `None` to keep default.
ttl: Option<u32>,
pub ttl: Option<u32>,
/// Keep alive duration to set for opened sockets, or `None` to keep default.
#[allow(clippy::option_option)]
keepalive: Option<Option<Duration>>,
pub keepalive: Option<Option<Duration>>,
/// `TCP_NODELAY` to set for opened sockets, or `None` to keep default.
nodelay: Option<bool>,
pub nodelay: Option<bool>,
}

impl TcpTransport {
Expand Down