Skip to content

fix: Use 1MB socket RX buffers #2470

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

Merged
merged 8 commits into from
Apr 2, 2025
Merged
Show file tree
Hide file tree
Changes from 5 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
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ enumset = { version = "1.1", default-features = false }
hex = { version = "0.4", default-features = false }
log = { version = "0.4", default-features = false }
qlog = { version = "0.15", default-features = false }
quinn-udp = { version = "0.5.10", default-features = false, features = ["direct-log", "fast-apple-datapath"] }
quinn-udp = { version = "0.5.11", default-features = false, features = ["direct-log", "fast-apple-datapath"] }
regex = { version = "1.9", default-features = false }
static_assertions = { version = "1.1", default-features = false }
strum = { version = "0.26", default-features = false, features = ["derive"] }
Expand Down
26 changes: 24 additions & 2 deletions neqo-bin/src/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

use std::{io, net::SocketAddr};

use neqo_common::Datagram;
use neqo_common::{qdebug, Datagram};
use neqo_udp::{DatagramIter, RecvBuf};

/// Ideally this would live in [`neqo-udp`]. [`neqo-udp`] is used in Firefox.
Expand All @@ -26,10 +26,32 @@ pub struct Socket {
impl Socket {
/// Create a new [`Socket`] bound to the provided address, not managed externally.
pub fn bind<A: std::net::ToSocketAddrs>(addr: A) -> Result<Self, io::Error> {
const ONE_MB: usize = 1 << 20;
let socket = std::net::UdpSocket::bind(addr)?;
let state = quinn_udp::UdpSocketState::new((&socket).into())?;

let send_buf = state.send_buffer_size((&socket).into())?;
// FIXME: We need to experiment if increasing this actually improves performance.
// Also, on BSD and Apple targets, this seems to increase the `net.inet.udp.maxdgram`
// sysctl, which is not the same as the socket buffer.
// if send_buf < ONE_MB {
// qdebug!("Increasing socket send buffer size from {send_buf} to {ONE_MB}");
// state.set_send_buffer_size((&socket).into(), ONE_MB)?;
// } else {
// qdebug!("Default socket send buffer size is {send_buf}, not changing");
// }
qdebug!("Default socket send buffer size is {send_buf}");

let recv_buf = state.recv_buffer_size((&socket).into())?;
if recv_buf < ONE_MB {
qdebug!("Increasing socket receive buffer size from {recv_buf} to {ONE_MB}");
state.set_recv_buffer_size((&socket).into(), ONE_MB)?;
} else {
qdebug!("Default socket receive buffer size is {recv_buf}, not changing");
}

Ok(Self {
state: quinn_udp::UdpSocketState::new((&socket).into())?,
state,
inner: tokio::net::UdpSocket::from_std(socket)?,
})
}
Expand Down
Loading