From 2101d8264c6657e2b71d29e540866c67a26843e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20M=C3=A4rtens?= Date: Tue, 4 Jul 2023 23:32:26 +0200 Subject: [PATCH] xVAR did some research here: https://discord.com/channels/449602562165833758/450065987006496768/979121835801202688 and because of that we decided to set the recv buffer to 512kB via linux kernel parameters. We didn't had any problems on the official server so we wanted to bake that into code. There is a calculator https://www.switch.ch/network/tools/tcp_throughput/?mss=1460&rtt=80&loss=1e-06&bw=10&rtt2=500&win=1024&Calculate=Calculate that said for 10Mbits/ speed 16kB recv buffer and 500ms we only can expect effective 0.24 Mbits of actuall data speed. Nothing mentioned increasing the send buffer, but it prob cant hurt from a server side or ? cat /proc/sys/net/core/wmem_default showed 212992 cat /proc/sys/net/core/rmem_default showed 212992 sysctl -w net.ipv4.tcp_wmem="4096 524288 4194304" was beeing used sysctl -w net.ipv4.tcp_wmem="4096 16384 4194304" was the default --- network/src/channel.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/network/src/channel.rs b/network/src/channel.rs index 8431eab186..a1a1a34ad2 100644 --- a/network/src/channel.rs +++ b/network/src/channel.rs @@ -122,6 +122,14 @@ impl Protocols { // See https://docs.rs/tokio/latest/tokio/net/struct.TcpSocket.html #[cfg(not(windows))] socket2_socket.set_reuse_address(true)?; + const SEND_BUFFER_SIZE: usize = 262144; + const RECV_BUFFER_SIZE: usize = SEND_BUFFER_SIZE * 2; + if let Err(e) = socket2_socket.set_recv_buffer_size(RECV_BUFFER_SIZE) { + warn!(?e, "Couldn't set recv_buffer size") + }; + if let Err(e) = socket2_socket.set_send_buffer_size(SEND_BUFFER_SIZE) { + warn!(?e, "Couldn't set set_buffer size") + }; let socket2_addr = addr.into(); socket2_socket.bind(&socket2_addr)?; socket2_socket.listen(1024)?;