]> mop.ddnsfree.com - git repositories - brisk.git/commitdiff
the listen queue of the daemon sockets was the default one
authorMatteo Nastasi <nastasi@alternativeoutput.it>
Sun, 13 Sep 2026 10:37:01 +0000 (12:37 +0200)
committerMatteo Nastasi <nastasi@alternativeoutput.it>
Sun, 13 Sep 2026 10:37:01 +0000 (12:37 +0200)
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) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014M1jiEq9cHdE5SE5j6vFuE

web/Obj/sac-a-push.phh
web/spush/brisk-spush.phh

index 9002acaf202b18851641fdccd70544d60749395c..06b3c0bdc915b44cd233cf52850e1736449ab5a1 100644 (file)
@@ -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);
index 5fdb783022b635e6c6b7f69df7a018f7552b139e..4eb2c35784c954a52cd774dc00a969277fc03942 100644 (file)
@@ -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.