From 2ef0c215ea4af421a4b22ab543a5999320998f68 Mon Sep 17 00:00:00 2001 From: Christophe Besson Date: Sun, 11 Oct 2026 20:47:42 +0200 Subject: fix(node): a receive buffer that holds an upload's window Uploads ran at 6.5 MB/s because the kernel dropped datagrams at the node's 256 KB socket. Asking for 4 MB gave 19.5 MB/s, no drop. Co-Authored-By: Claude Opus 5.5 --- packages/meshbay-node/tests/test_udp_buffer.py | 38 ++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 packages/meshbay-node/tests/test_udp_buffer.py (limited to 'packages/meshbay-node/tests/test_udp_buffer.py') diff --git a/packages/meshbay-node/tests/test_udp_buffer.py b/packages/meshbay-node/tests/test_udp_buffer.py new file mode 100644 index 0000000..2159663 --- /dev/null +++ b/packages/meshbay-node/tests/test_udp_buffer.py @@ -0,0 +1,38 @@ +""" +The node's ICE sockets ask for a receive buffer that holds an upload's window. + +Measured on a node in service: during a 200 MB upload from a browser 22 ms +away the node's machine dropped 2460 of 264000 datagrams at the socket +(`Udp6RcvbufErrors`), with a buffer of 512 KB, and the upload ran at 6.4 MB/s. +The browser keeps 32 chunks of 48 KB in flight, 1.5 MB, and the kernel counts +about twice the bytes it holds. +""" + +import socket + +import aioice +import pytest +from meshbay_node.transport.webrtc import udp_buffer + + +def test_the_request_covers_what_an_upload_keeps_in_flight(): + in_flight = 32 * 48 * 1024 + assert udp_buffer.WANTED >= 2 * in_flight + assert aioice.turn.UDP_SOCKET_BUFFER_SIZE == udp_buffer.WANTED + + +@pytest.mark.asyncio +async def test_a_gathered_socket_gets_what_the_kernel_allows(): + """aioice reads the constant when it gathers, not when it is imported: the + socket of a real candidate has the buffer, up to the machine's ceiling.""" + conn = aioice.Connection(ice_controlling=True) + try: + await conn.gather_candidates() + sizes = [p.transport.get_extra_info("socket").getsockopt( + socket.SOL_SOCKET, socket.SO_RCVBUF) + for p in conn._protocols] + assert sizes, "no candidate was gathered" + assert min(sizes) == udp_buffer.granted() + assert min(sizes) > 262144, "the machine grants no more than aioice asked before" + finally: + await conn.close() -- cgit v1.2.3