From 8042e9ad14933f3af69fe61a32a6e0b8c2815ca4 Mon Sep 17 00:00:00 2001 From: Matteo Nastasi Date: Sun, 13 Sep 2026 12:37:01 +0200 Subject: [PATCH] the listen queue of the daemon sockets was the default one With the php default backlog a single socket of the pool queues 111 connections and then refuses: measured with a burst of 300 simultaneous connects. The frontend gets EAGAIN on the connect and has to fall back on another socket of the pool, or return an error. It showed up during the load test: with 300 entries close together nginx logged "connect() to unix:...brisk0.sock failed (11: Resource temporarily unavailable)". With the backlog at 511 the same burst goes through entirely and the error does not come back. Until now the pool of ten sockets masked the problem, spreading the connections over ten short queues instead of one long queue. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_014M1jiEq9cHdE5SE5j6vFuE --- web/Obj/sac-a-push.phh | 15 +++++++++++++-- web/spush/brisk-spush.phh | 3 +++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/web/Obj/sac-a-push.phh b/web/Obj/sac-a-push.phh index 9002aca..06b3c0b 100644 --- a/web/Obj/sac-a-push.phh +++ b/web/Obj/sac-a-push.phh @@ -607,15 +607,26 @@ class Sac_a_push { unlink($file_socket_admin); } + /* The default listen queue (128) is short for a full room: if many + players come in at the same instant the frontend gets EAGAIN on the + connect and has to fall back on another socket of the pool. + Measured: with the default a single socket queues 111 of them and + refuses the rest. */ + $ctx = stream_context_create(array('socket' => array('backlog' => USOCK_BACKLOG))); + $old_umask = umask(0); for ($i = 0 ; $i < USOCK_POOL_N ; $i++) { $unix_socket = sprintf("%s%d.sock", $thiz->unix_socket_pfx, $i); - if (($list_sock = stream_socket_server($unix_socket, $err, $errs)) === FALSE) { + if (($list_sock = stream_socket_server($unix_socket, $err, $errs, + STREAM_SERVER_BIND | STREAM_SERVER_LISTEN, + $ctx)) === FALSE) { return (FALSE); } array_push($thiz->list_web, $list_sock); } - if (($thiz->list_cmd = stream_socket_server($thiz->direct_socket, $err, $errs)) === FALSE) { + if (($thiz->list_cmd = stream_socket_server($thiz->direct_socket, $err, $errs, + STREAM_SERVER_BIND | STREAM_SERVER_LISTEN, + $ctx)) === FALSE) { return (FALSE); } umask($old_umask); diff --git a/web/spush/brisk-spush.phh b/web/spush/brisk-spush.phh index 5fdb783..4eb2c35 100644 --- a/web/spush/brisk-spush.phh +++ b/web/spush/brisk-spush.phh @@ -26,6 +26,9 @@ $DOCUMENT_ROOT=""; $HTTP_HOST="dodo.birds.lan"; define('USOCK_PATH_PFX', "/tmp/brisk"); define('USOCK_POOL_N', 10); +/* length of the listen queue of every socket in the pool: with the php + default (128) a burst of simultaneous entries is partly refused */ +define('USOCK_BACKLOG', 511); /* How the daemon gets the player connection. -- 2.47.3