How Many TCP Connections Can One Server Really Handle? A Deep Dive into Linux Limits
This article demystifies common misconceptions about server concurrency, explains the theoretical maximum TCP connections based on the four‑tuple, details Linux file‑descriptor and buffer limits, and walks through a practical experiment that achieves over one million simultaneous connections on a single machine.
TCP Four‑Tuple Theoretical Limit
TCP connections are identified by a four‑tuple: source IP, source port, destination IP, and destination port. With a fixed server IP and port (e.g., Nginx on port 80), the variable elements are source IP and source port, giving a theoretical maximum of 2³² × 2¹⁶ ≈ 2.8 × 10¹⁴ possible connections.
Linux File‑Descriptor Limits
Each opened file (including sockets) consumes kernel memory. Linux enforces limits on the number of open file descriptors at three levels:
System‑wide limit: configurable via fs.file-max User‑level limit: set in /etc/security/limits.conf Process‑level limit: configurable via
fs.nr_openSocket Buffer Settings
The receive buffer size can be inspected and tuned with sysctl . The first value in net.ipv4.tcp_rmem is the minimum per‑socket receive buffer (default 4 KB), the third value is the maximum (default 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 . The first value is the minimum send buffer (default 4 KB), and the third value is the maximum (default 8 MB).
$ sysctl -a | grep wmem
net.ipv4.tcp_wmem = 4096 65536 8388608
net.core.wmem_default = 212992
net.core.wmem_max = 8388608Achieving One Million Concurrent Connections
To reach 1 000 000 connections, the file‑descriptor limits were raised to 1.1 million at system, user, and process levels, leaving enough descriptors for auxiliary commands (e.g., ps , vi ).
$ ss -n | grep ESTAB | wc -l
1000024The test machine had 3.9 GB RAM; the kernel slab consumed about 3.2 GB, leaving roughly 100 MB for other uses.
$ cat /proc/meminfo
MemTotal: 3922956 kB
MemFree: 96652 kB
MemAvailable: 6448 kB
Buffers: 44396 kB
Slab: 3241244 kBUsing slabtop , the kernel objects densty , flip , sock_inode_cache , and TCP each showed roughly one million entries, confirming the connection count.
Conclusion
Understanding the TCP four‑tuple, Linux file‑descriptor limits, and socket buffer parameters allows a server to sustain well over a million simultaneous TCP connections on modest hardware when the limits are tuned appropriately.
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.
ITPUB
Official ITPUB account sharing technical insights, community news, and exciting events.
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.
