How Many TCP Connections Can One Server Really Handle? A Deep Dive
This article explains the true limits of simultaneous TCP connections on a single Linux server, debunking common myths about the 65,535 port ceiling, detailing kernel and user‑level file‑descriptor restrictions, sysctl buffer settings, and a practical experiment achieving one million concurrent connections.
Why the Max Connections Question Matters
Many developers mistakenly believe a server can only hold 65,535 TCP connections because the port number range ends at 65535, or they cite the theoretical 2^32 × 2^16 four‑tuple space yielding over two hundred trillion possibilities. This article clarifies the real constraints.
TCP Four‑Tuple and Theoretical Limits
TCP connections are identified by source IP, source port, destination IP, and destination port. Changing any element creates a distinct connection. For a fixed server IP (e.g., Nginx on port 80), only the source IP and source port vary, giving a theoretical maximum of 2^32 × 2^16 ≈ 200 trillion connections.
Linux File‑Descriptor Limits
Each opened file or socket consumes a file descriptor, which is limited for security and stability. Linux enforces limits at three levels:
System‑wide limit: fs.file-max (modifiable via sysctl)
User‑level limit: configured in /etc/security/limits.conf Process‑level limit: fs.nr_open (also adjustable with sysctl)
TCP Buffer Settings
The receive buffer size is configurable via net.ipv4.tcp_rmem . The first value is the minimum allocation per socket (default 4 KB, max 8 MB).
sysctl -a | grep rmem
net.ipv4.tcp_rmem = 4096 87380 8388608
net.core.rmem_default = 212992
net.core.rmem_max = 8388608The send buffer size is controlled by net.ipv4.tcp_wmem . Its first value is also the minimum (default 4 KB).
sysctl -a | grep wmem
net.ipv4.tcp_wmem = 4096 65536 8388608
net.core.wmem_default = 212992
net.core.wmem_max = 8388608Experiment: Achieving One Million Concurrent Connections
To test the limits, the author increased all three file‑descriptor limits to 1.1 million and ran a load test targeting 1 million connections. The result:
ss -n | grep ESTAB | wc -l
1000024Memory usage on the test machine (3.9 GB total) showed the kernel slab consuming ~3.2 GB, leaving only ~100 MB free:
cat /proc/meminfo
MemTotal: 3922956 kB
MemFree: 96652 kB
MemAvailable: 6448 kB
Buffers: 44396 kB
Slab: 3241244 kBUsing slabtop , the author observed that the kernel objects sock_inode_cache and TCP structures each held about one million entries.
Conclusion
The practical limit of concurrent TCP connections on a Linux server is governed not by the theoretical four‑tuple space but by configurable kernel parameters, file‑descriptor limits, and available memory. By tuning fs.file-max, fs.nr_open, user limits, and TCP buffer sizes, a single server can reliably handle on the order of one million simultaneous connections, provided sufficient RAM is available.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
