Linux VM and bare metal
Run Sockudo under systemd with correct file limits, measured kernel tuning, and a WebSocket-aware proxy.
This guide runs Sockudo as a systemd service on a Linux VM or physical host, then tunes file limits, the kernel, and the reverse proxy for long-lived WebSocket connections. Choose this path when you want direct control over the process and host, or when connection density matters more than orchestration features.
A Linux VM is often the simplest production deployment for a known, stable workload. It gives you direct control over file limits, kernel settings, CPU scheduling, network queues, and the process lifecycle. Start with one host only if a host restart is an acceptable outage; use at least two hosts and a shared adapter for availability.
Host layout
Use separate paths for the binary, configuration, secrets, and service account:
/usr/local/bin/sockudo/etc/sockudo/config.toml/etc/sockudo/sockudo.env/etc/systemd/system/sockudo.serviceRoot owns the binary and configuration so a compromised Sockudo process cannot rewrite them. The
sockudo group can read the configuration and secrets. Sockudo does not need root privileges when
it binds to ports 6001 and 9601, because both are above 1024.
Install the service
-
Create the service account and configuration directory:
Terminal window sudo useradd --system --home /var/lib/sockudo --create-home --shell /usr/sbin/nologin sockudosudo install -d -o root -g sockudo -m 0750 /etc/sockudoVerify with
id sockudo, which prints the new user and group. -
Install a pinned binary. With the release installer, download into a staging directory and then install it system-wide:
Terminal window curl --proto '=https' --tlsv1.2 -sSfL https://sockudo.io/install.sh \| sh -s -- --version 5.3.0 --bin-dir "$HOME/sockudo-5.3.0"sudo install -o root -g root -m 0755 "$HOME/sockudo-5.3.0/sockudo" /usr/local/bin/sockudoFrom a source build, install
target/release/sockudothe same way. Verify with/usr/local/bin/sockudo --version, which printssockudo 5.3.0. -
Install the configuration and the secret environment file:
Terminal window sudo install -o root -g sockudo -m 0640 config/production.toml /etc/sockudo/config.tomlsudo install -o root -g sockudo -m 0640 /dev/null /etc/sockudo/sockudo.envsudoedit /etc/sockudo/sockudo.envKeep
sockudo.envat mode0640or stricter. Verify withls -l /etc/sockudo: both files show-rw-r-----and groupsockudo. -
Write the systemd unit from the next section to
/etc/systemd/system/sockudo.service. -
Start the service and enable it at boot:
Terminal window sudo systemctl daemon-reloadsudo systemctl enable --now sockudosudo systemctl status sockudostatusmust showactive (running). Confirm the configuration source and health:Terminal window journalctl -u sockudo -b | grep -E 'explicit configuration applied|applied environment variable overrides'curl -fsS http://127.0.0.1:6001/up/<app-id>The
curlcommand printsOK.
Do not put secrets directly in the systemd unit. Unit contents are commonly collected in
diagnostics and configuration management, and systemctl show exposes them to local users.
systemd unit
[Unit]Description=Sockudo realtime serverWants=network-online.targetAfter=network-online.target
[Service]Type=simpleUser=sockudoGroup=sockudoWorkingDirectory=/var/lib/sockudoEnvironmentFile=-/etc/sockudo/sockudo.envExecStart=/usr/local/bin/sockudo --config /etc/sockudo/config.tomlRestart=on-failureRestartSec=2sLimitNOFILE=1048576TimeoutStopSec=120sKillSignal=SIGTERMNoNewPrivileges=truePrivateTmp=truePrivateDevices=trueProtectSystem=strictProtectHome=trueProtectKernelTunables=trueProtectKernelModules=trueProtectControlGroups=trueRestrictSUIDSGID=trueLockPersonality=true
[Install]WantedBy=multi-user.targetWhy the key directives matter:
--configis explicit, so the result does not depend onWorkingDirectory. A file that fails to load stops startup, andRestart=on-failureretries it every two seconds; checkjournalctl -u sockudowhen the unit flaps.LimitNOFILEis the only reliable way to raise the open-file limit for a systemd service. Every socket is a file descriptor.TimeoutStopSecis how long systemd waits afterSIGTERMbefore it sendsSIGKILL. A kill during drain can lose buffered webhook and lifecycle events.- The
Protect*,Private*, andRestrict*directives remove filesystem and kernel access that Sockudo does not need.
Set TimeoutStopSec above shutdown_grace_period plus twice
queue.reliability.shutdown_timeout_ms / 1000, with additional time for connection and backend
teardown. The two budgets cover webhook draining and
queue worker shutdown.
For example (illustrative): with shutdown_grace_period = 30 and the default
shutdown_timeout_ms = 30000, the drain can take 30 + 2 × 30 = 90 seconds. Adding 30 seconds for
teardown gives the TimeoutStopSec=120s shown above. Recalculate when you change either value.
Add ReadWritePaths= only when a selected feature writes to local disk. A stricter security
directive may need adjustment for a provider SDK or a TLS key path; keep any exception narrow.
File descriptor limits
Every accepted socket consumes a file descriptor, as do logs, shared-backend connections, metrics,
and internal listeners. When the process reaches its limit, new connections fail at accept even
though CPU and memory look healthy. Budget:
required nofile >= planned sockets + backend connections + listeners + operational reserveFor example (illustrative): 100,000 planned sockets, 200 backend connections, and 10 listeners
with a 20% reserve need (100,000 + 200 + 10) × 1.2 ≈ 120,252 descriptors. The unit’s
LimitNOFILE=1048576 covers that comfortably.
Use at least 10–20% reserve and never set SOCKUDO_MAX_CONNECTIONS equal to the hard nofile
limit.
Verify the running process rather than the shell:
systemctl show sockudo -p LimitNOFILEcat /proc/"$(pidof sockudo)"/limits | grep -i 'open files'ls /proc/"$(pidof sockudo)"/fd | wc -lThe first two commands should both report 1048576; the third shows how many descriptors the
process holds right now.
Also check system-wide pressure:
sysctl fs.file-max fs.nr_opencat /proc/sys/fs/file-nrThe first field of file-nr is the number of allocated file handles; it should stay well below
fs.file-max.
Baseline kernel profile
Treat this as a starting profile for a dedicated Sockudo node, not a universal requirement:
# Listen and SYN queues for connection bursts.net.core.somaxconn = 65535net.ipv4.tcp_max_syn_backlog = 65535
# Input backlog; raise only when packet drops show the default is too small.net.core.netdev_max_backlog = 16384
# Detect dead peers eventually at the TCP layer. Sockudo protocol heartbeats# remain the primary application-level liveness mechanism.net.ipv4.tcp_keepalive_time = 600net.ipv4.tcp_keepalive_intvl = 60net.ipv4.tcp_keepalive_probes = 5
# Avoid restarting congestion control from the initial window after idle.net.ipv4.tcp_slow_start_after_idle = 0Apply and verify:
sudo sysctl --systemsysctl net.core.somaxconn net.ipv4.tcp_max_syn_backlogsysctl net.core.netdev_max_backlogsysctl net.ipv4.tcp_keepalive_time net.ipv4.tcp_keepalive_intvl net.ipv4.tcp_keepalive_probesEach sysctl line must print the value from the file, for example net.core.somaxconn = 65535.
Why these are not all “set once and forget” values:
- a larger
somaxconnhelps only if the application’s listen backlog and accept loop can use it - a larger SYN queue helps connection bursts, such as every client reconnecting after a node restart, not steady-state message fanout
- a larger
netdev_max_backlogcan trade drops for latency and memory when CPU is already saturated - TCP keepalive does not replace Sockudo’s protocol ping/pong and should not fire more aggressively than necessary
tcp_slow_start_after_idle = 0matters for realtime traffic because quiet sockets are idle most of the time; without it, the first burst after a pause starts from a small congestion window- modern Linux already autotunes TCP buffers; raising
rmem_maxandwmem_maxwithout high bandwidth-delay-product evidence can increase per-socket memory risk
Optional settings such as tcp_fin_timeout, socket buffer ceilings, IRQ affinity, CPU isolation,
busy polling, and NIC ring sizes should follow a measured bottleneck. Record the before/after
kernel counters and repeat the same workload.
Inspect the network path
Useful counters during a connect or reconnect surge:
ss -sss -lntnstat -az | grep -E 'ListenOverflows|ListenDrops|TCPBacklogDrop|TCPSynRetrans'ip -s linkethtool -S eth0Interpret them together:
ListenOverflowsorListenDropssuggests the accept/listen path cannot keep up- interface drops suggest host networking, vNIC, or CPU pressure
- SYN retransmits can be the client network, load balancer, firewall, or server
- no server-side drops with low achieved load usually points upstream or at the generator
Reverse proxy example
Terminate TLS at a load balancer or a carefully configured reverse proxy. A WebSocket starts as an
HTTP/1.1 request with Upgrade: websocket; a proxy that does not forward those headers turns every
connection attempt into a plain HTTP request. NGINX needs HTTP/1.1 upgrade forwarding and long
enough timeouts:
map $http_upgrade $connection_upgrade { default upgrade; '' close;}
upstream sockudo { least_conn; server 10.0.1.10:6001 max_fails=3 fail_timeout=10s; server 10.0.2.10:6001 max_fails=3 fail_timeout=10s;}
server { listen 443 ssl; server_name ws.example.com;
location / { proxy_pass http://sockudo; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_read_timeout 180s; proxy_send_timeout 180s; proxy_buffering off; }}least_conn sends each new connection to the backend with the fewest active connections, which
suits long-lived sockets better than round robin. proxy_buffering off stops NGINX from holding
realtime frames in a buffer.
The default Sockudo activity_timeout is 120 seconds. Set every proxy or load-balancer idle timeout
above the longest expected interval between application or heartbeat traffic, with margin. A
180-second starting value works with the default, but validate it with the actual client SDKs and
network path.
Client IP behind the proxy
If the proxy adds entries to X-Forwarded-For, configure RATE_LIMITER_API_TRUST_HOPS and
RATE_LIMITER_WS_TRUST_HOPS to the client’s one-based position from the right of that header.
For the NGINX configuration above, use 1: $proxy_add_x_forwarded_for appends the client’s
address, so a client-supplied prefix is ignored. Other platforms can append more than one entry;
Google’s external Application Load Balancer appends <client>, <load-balancer>, requiring 2
when it connects directly to Sockudo. Validate the actual path rather than counting proxy machines.
Only enable forwarding-header trust when direct access to Sockudo is restricted to your proxies
and those proxies sanitize or append the headers. A hop count does not authenticate the socket
peer. With 0, both X-Forwarded-For and X-Real-IP are ignored. Invalid or short chains fall
back to the socket peer, with a once-only warning containing no header values. See
client IP extraction for migration details.
One host versus several
| Concern | One host | Two or more hosts |
|---|---|---|
| Adapter | local is valid | Use Redis, NATS, or another horizontal adapter |
| App definitions | Static memory app can work | All nodes need identical static apps, or use a shared app manager |
| Rate limits | Memory is per host | Use Redis or Redis Cluster for cluster-wide limits |
| Queue | Memory work is lost with the host | Use a durable shared queue for webhooks and push |
| History and mutations | Memory can be acceptable for tests | Use a supported durable backend |
| Load balancer | Optional reverse proxy | Required, with health checks and drain |
For multiple nodes, set fallback_to_local = false. The default is true, which lets a node that
cannot reach its horizontal adapter at startup run alone. A production cluster should fail startup
when its horizontal adapter is unavailable instead of silently splitting into isolated local
islands.
Drain and upgrade
On SIGTERM, Sockudo marks itself as draining (/up and /ready return 503 DRAINING), rejects
new WebSocket upgrades, closes existing connections with code 4200 so clients reconnect elsewhere,
and keeps the listener open for shutdown_grace_period seconds. See
rolling deploys for the full sequence and the
shutdown_close_delay_ms and shutdown_close_spread_ms pacing options.
- Remove the host from load-balancer rotation. If you skip this, the balancer’s health check
still sees
503 DRAININGonce Sockudo stops, but only after its probe interval. - Wait for the balancer’s deregistration delay or connection drain policy.
- Stop Sockudo with
sudo systemctl stop sockudo.TimeoutStopSecmust cover Sockudo’s listener grace, webhook drain, queue worker shutdown, and teardown. - Replace the binary and configuration atomically, for example with
installto a new path followed bymv. - Start the service with
sudo systemctl start sockudo. - Wait until
curl -fsS http://127.0.0.1:6001/up/<app-id>printsOK, then restore load-balancer membership.
Watch reconnect attempts, recovery success, adapter errors, and connection distribution throughout the rollout.
Production checklist
/usr/local/bin/sockudo --versionreports the intended release on every host/proc/<pid>/limitsshows the intendedMax open filesSOCKUDO_MAX_CONNECTIONS(ormax_connections) is set below the measured safe ceilingTimeoutStopSecexceeds the drain budget calculated above- the sysctl profile is applied after reboot (
sysctl --systemreads/etc/sysctl.d) - proxy idle timeouts exceed the heartbeat interval, verified with a quiet client
- the metrics port
9601is reachable only from your monitoring network fallback_to_local = falseon every node of a multi-host deployment