Skip to content

Commit 9354a53

Browse files
larseggertmxinden
andauthored
fix: Use 1MB socket RX buffers (#2470)
* fix: Use 1MB socket TX and RX buffers We need to do the same for `neqo-glue`. Fixes #1962 * Windows * Undo * Leave the TX buffer alone for now * Update neqo-bin/src/udp.rs Co-authored-by: Max Inden <[email protected]> Signed-off-by: Lars Eggert <[email protected]> * Log result size * fmt --------- Signed-off-by: Lars Eggert <[email protected]> Co-authored-by: Max Inden <[email protected]>
1 parent 7d40924 commit 9354a53

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

Cargo.lock

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ enumset = { version = "1.1", default-features = false }
3434
hex = { version = "0.4", default-features = false }
3535
log = { version = "0.4", default-features = false }
3636
qlog = { version = "0.15", default-features = false }
37-
quinn-udp = { version = "0.5.10", default-features = false, features = ["direct-log", "fast-apple-datapath"] }
37+
quinn-udp = { version = "0.5.11", default-features = false, features = ["direct-log", "fast-apple-datapath"] }
3838
regex = { version = "1.9", default-features = false }
3939
static_assertions = { version = "1.1", default-features = false }
4040
strum = { version = "0.26", default-features = false, features = ["derive"] }

neqo-bin/src/udp.rs

+28-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

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

11-
use neqo_common::Datagram;
11+
use neqo_common::{qdebug, Datagram};
1212
use neqo_udp::{DatagramIter, RecvBuf};
1313

1414
/// Ideally this would live in [`neqo-udp`]. [`neqo-udp`] is used in Firefox.
@@ -26,10 +26,36 @@ pub struct Socket {
2626
impl Socket {
2727
/// Create a new [`Socket`] bound to the provided address, not managed externally.
2828
pub fn bind<A: std::net::ToSocketAddrs>(addr: A) -> Result<Self, io::Error> {
29+
const ONE_MB: usize = 1 << 20;
2930
let socket = std::net::UdpSocket::bind(addr)?;
31+
let state = quinn_udp::UdpSocketState::new((&socket).into())?;
32+
33+
let send_buf_before = state.send_buffer_size((&socket).into())?;
34+
// FIXME: We need to experiment if increasing this actually improves performance.
35+
// Also, on BSD and Apple targets, this seems to increase the `net.inet.udp.maxdgram`
36+
// sysctl, which is not the same as the socket buffer.
37+
// if send_buf_before < ONE_MB {
38+
// state.set_send_buffer_size((&socket).into(), ONE_MB)?;
39+
// let send_buf_after = state.send_buffer_size((&socket).into())?;
40+
// qdebug!("Increasing socket send buffer size from {send_buf_before} to {ONE_MB}, now:
41+
// {send_buf_after}"); } else {
42+
// qdebug!("Default socket send buffer size is {send_buf_before}, not changing");
43+
// }
44+
qdebug!("Default socket send buffer size is {send_buf_before}");
45+
46+
let recv_buf_before = state.recv_buffer_size((&socket).into())?;
47+
if recv_buf_before < ONE_MB {
48+
// Same as Firefox.
49+
// <https://searchfox.org/mozilla-central/source/modules/libpref/init/StaticPrefList.yaml#13474-13478>
50+
state.set_recv_buffer_size((&socket).into(), ONE_MB)?;
51+
let recv_buf_after = state.recv_buffer_size((&socket).into())?;
52+
qdebug!("Increasing socket recv buffer size from {recv_buf_before} to {ONE_MB}, now: {recv_buf_after}");
53+
} else {
54+
qdebug!("Default socket receive buffer size is {recv_buf_before}, not changing");
55+
}
3056

3157
Ok(Self {
32-
state: quinn_udp::UdpSocketState::new((&socket).into())?,
58+
state,
3359
inner: tokio::net::UdpSocket::from_std(socket)?,
3460
})
3561
}

0 commit comments

Comments
 (0)