Capacity and tuning#
- Linux limits (for a busy balancer; adjust to your load):
- open files:
MAX_OPEN_FILESat the top ofcrushbalance_init.sh(1048576 as delivered; Install on Linux).installwrites it into the systemd unit asLimitNOFILE, andstartsets it withulimit -n, as far as the user may go. The automatic global connection cap (max_connections= 0) is (open-file limit − 1024) ÷ 2, at least 1,000, so a low limit also lowers the cap; net.core.somaxconn=65535andnet.ipv4.tcp_max_syn_backlog=65535;- the ephemeral port range:
net.ipv4.ip_local_port_range="1024 65535". Reserve the ports of your listeners in it, passive ranges included, for examplenet.ipv4.ip_local_reserved_ports="21,443,990,40000-40999": otherwise a connection to a backend can take a listener's port while that listener is not bound (at startup, or after a change), and the listener stays inbind_erroruntil that connection closes. The default range (32768–60999) already contains common passive ranges; net.ipv4.tcp_tw_reuse=1andnet.ipv4.tcp_max_tw_bucketsof at least 2,000,000;- conntrack:
net.netfilter.nf_conntrack_maxsized for 120 seconds of connections at the peak rate, or conntrack disabled for the balanced ports; fs.file-maxabove twice the number of sessions.
- open files:
- Heap (preliminary). The final sizing table comes with the load tests on reference hardware (three Linux hosts, 100,000 sessions from 8 client addresses). Until then use these figures:
-Xmx1024Mcovers about 100,000 plain or about 40,000 TLS sessions, or about 30,000 re-encrypting HTTPS sessions (backend_tls, which holds a second TLS engine per session).- Local load tests, with at most 4,480 sessions from one client address, confirm the first two figures with margin. They measured this heap per idle session: about 2.3 KB for a plain
tcpsession, about 8 KB for a TLS-terminated one, about 8.4–9.1 KB for HTTPS with plain back legs, and about 14.1–14.6 KB for HTTPS re-encrypting to CrushMFT. Each distinct client address adds roughly 0.2–0.3 KB (measured with IP stickiness, without a per-client cap or GeoIP, which keep an entry per address of their own). For a mix, add the costs. - Keep that live heap, about 8 MB plus the sessions, at or below about 45 % of
-Xmx: the rest absorbs TLS handshakes in flight (about 3 KB each) and the short-lived garbage of TLS transfers. - Plan the process's memory as
-Xmxplus about 0.4 GB (thread stacks and the garbage collector), plus the direct memory of the data buffers in use (below), plus the kernel's socket buffers. - To raise the heap on Linux, edit
-Xmx1024MinJAVA_OPTSat the top ofcrushbalance_init.sh; on Windows, run-i [heapMB]again. - Data buffers live in direct memory (a quarter of the JVM's maximum direct memory, 64 MiB–4 GiB); by default the JDK sizes direct memory like the heap, so raising
-Xmxraises it too.
- Local load tests, with at most 4,480 sessions from one client address, confirm the first two figures with margin. They measured this heap per idle session: about 2.3 KB for a plain
- Very high churn to one backend. When the client closes first, the balancer's connection to the backend waits in TIME_WAIT. With default settings that limits new sessions to one backend address and port to roughly 470 per second; the settings above raise it, and several backend addresses or ports raise it further.
- Windows: widen the dynamic port range (
netsh int ipv4 set dynamicport tcp start=10000 num=55535) and shortenTcpTimedWaitDelay(registry value underHKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters).