Skip to content

Workers

One proxy process uses one CPU core. To use more, run several workers on the same ports, one per core:

Terminal window
proxium --workers 4 # or PROXY_WORKERS=4
docker run -e PROXY_WORKERS=4 ... ikoldakov/proxium

Linux spreads new connections between the workers. Connection limits, speed limits and quotas hold across them through Redis, as across instances. In the admin they are one proxy instance, its Workers column says how many serve, e.g. 3 / 4 while one restarts.

  • Each worker has its own database and Redis pools (DATABASE_POOL_* and REDIS_POOL_MAX_CONNECTIONS apply to each), client caches and settings lookups: those grow with the count, connections don’t get slower.
  • Several workers need PROXY_REUSE_PORT=true, see Configuration.
  • On macOS the kernel doesn’t balance them: several workers are for Linux.

A master process runs the workers, one by default, and reports the proxy to the admin. SIGINT or SIGTERM goes to every worker, each finishes its open connections, a second signal stops at once.

  • A worker that crashes is restarted in a second, one that keeps crashing waits twice as long each time, up to 30 seconds.
  • One that fails its first start, e.g. on an invalid policy or a taken port, stops the whole proxy with exit code 1.
  • A restart that fails, e.g. while the database is down, is a crash like any other: the rest keep serving.

A connection lives in the worker that accepted it: if that worker crashes or is killed, its open connections are cut, and clients reconnect to the others. No other worker can take them over, their TLS and tunnel state was in the gone process. A SIGTERM loses nothing: the worker finishes them first.

Connections waiting to be accepted are queued per worker, and reset with it too. On Linux 5.14 and newer the kernel can move them to another worker’s queue instead:

Terminal window
sysctl -w net.ipv4.tcp_migrate_req=1 # on the host, e.g. in /etc/sysctl.d/
docker run --sysctl net.ipv4.tcp_migrate_req=1 ... # in a container, not with --network host

It covers restarts without downtime too: the old proxy’s queue goes to the new one.