From 6e72929999ca52bd9f16fa9ab71eb1ddb473191d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=A3rebe=20-=20Romain=20GERARD?= Date: Thu, 26 Oct 2023 09:01:46 +0200 Subject: [PATCH] feat: improve udp max throughput --- src/udp.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/udp.rs b/src/udp.rs index fdef752..6ff7416 100644 --- a/src/udp.rs +++ b/src/udp.rs @@ -16,7 +16,7 @@ use tokio::net::UdpSocket; use tokio::time::Sleep; use tracing::{debug, error, info}; -const DEFAULT_UDP_BUFFER_SIZE: usize = 8 * 1024; +const DEFAULT_UDP_BUFFER_SIZE: usize = 64 * 1024; // 64kb struct UdpServer { listener: Arc, @@ -154,7 +154,7 @@ pub async fn run_server( match server.peers.entry(peer_addr) { Entry::Occupied(mut peer) => { - let ret = peer.get_mut().write_all(&server.buffer[0..nb_bytes]).await; + let ret = peer.get_mut().write_all(&server.buffer[..nb_bytes]).await; if let Err(err) = ret { info!("Peer {:?} disconnected {:?}", peer_addr, err); peer.remove(); @@ -162,7 +162,7 @@ pub async fn run_server( } Entry::Vacant(peer) => { let (mut rx, tx) = tokio::io::duplex(DEFAULT_UDP_BUFFER_SIZE); - rx.write_all(&server.buffer[0..nb_bytes]) + rx.write_all(&server.buffer[..nb_bytes]) .await .unwrap_or_default(); // should never fail peer.insert(rx);