Clients of TCP services on event loops, served by fibers

With -L, or loopmode on for the services which follow, the clients of a
TCP service are served on event loops: loops threads (by default one
for each CPU) each run a loop, and each client is given in turn to one
of them, which serves it on a fiber with the same code a thread runs.
Its waits in sockpoll() wait in the loop, its sockets and a timer
registered there, and the fiber goes on once one is ready or the time
is out; a sleep is a timer alone. A client costs a stack, as large as
its thread's would be, and no thread. The loops start with the first
client served on one and run as long as the process; each keeps up to
256 idle fibers for its next clients.

srvspawn() posts the client to its loop once it is counted, what is
posted made before so that posting cannot fail. A service whose clients
cannot share a thread (threadperclient), or listening for connections
back (-R), all of its clients waiting for one socket, which a loop
waits for once, keeps a thread for each client, as does every service
of a build or a processor without fibers, and the standalone services.

tests/run.py --loopmode runs every configuration with loopmode on, on
two loops.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Vladimir DubrovinandClaude Opus 5.5 committed 2026-10-24 23:00:16 +03:00
1 parent e250f98598
commit c55f736a0d
11 files changed
+489 -20

No files matched your search

+3
View File
@@ -751,6 +751,7 @@ struct srvparam {
/* a thread for each client: what serves them waits other than in
sockpoll(), or must not be left by a thread to serve another */
int threadperclient;
int loopmode; /* its clients served on event loops */
struct extparam *config; /* the configuration it was started with */
int timeouts[12]; /* conf.timeouts as they were when the service started */
int filtermaxsize, parentretries, maxseg; /* and these */
@@ -1000,6 +1001,8 @@ struct extparam {
unsigned authcachetype, authcachetime;
int filtermaxsize;
int poolmax, pooltimeout; /* threadpool: idle workers kept, -1 automatic */
int loops; /* threads serving clients on event loops, 0: a CPU each */
int loopmode; /* services from here on serve clients on loops */
int gracetraf, gracenum, gracedelay;
int maxseg;
unsigned char **archiver;