aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-node/tests/test_udp_buffer.py
diff options
context:
space:
mode:
authorChristophe Besson <cbesson@gmail.com>2026-10-11 20:47:42 +0200
committerChristophe Besson <cbesson@gmail.com>2026-10-11 20:47:42 +0200
commit2ef0c215ea4af421a4b22ab543a5999320998f68 (patch)
treed0c5d25fca95042c3c58724e1058f4d56b415f9f /packages/meshbay-node/tests/test_udp_buffer.py
parent176b5ed563f7022009b70751e62b7ee7901e6da0 (diff)
downloadmeshbay-2ef0c215ea4af421a4b22ab543a5999320998f68.tar.gz
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 <noreply@anthropic.com>
Diffstat (limited to 'packages/meshbay-node/tests/test_udp_buffer.py')
-rw-r--r--packages/meshbay-node/tests/test_udp_buffer.py38
1 files changed, 38 insertions, 0 deletions
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()