Sobes.tech
Senior

What is the maximum number of TCP connections that can be held on a single server?

sobes.tech AI

Answer from AI

The maximum number of TCP connections on a single server depends on several factors:

  1. Operating System Limitations:

    • The maximum number of open file descriptors, since each connection is a descriptor.
    • Kernel settings, such as the maximum number of sockets.
  2. Hardware Resources:

    • Amount of RAM.
    • Processor power.
  3. Network stack and application configuration:

    • Buffer sizes.
    • Efficiency of connection handling.

In Linux, the default limit on open files can be around several tens of thousands (e.g., 1024 or 4096), but it can be increased to hundreds of thousands or millions.

Practically, modern servers can support hundreds of thousands of TCP connections if the OS and application are properly configured. For example, nginx and other high-performance servers successfully handle 100,000+ concurrent connections.

In Go, the number of simultaneously open TCP connections is limited by the same factors, plus possible restrictions of the application itself.

To increase limits, you need to:

  • Increase the open files limit (ulimit -n).
  • Configure kernel parameters (sysctl), such as net.core.somaxconn, net.ipv4.ip_local_port_range.
  • Optimize the application for asynchronous processing.

Thus, there is no exact number, but with proper configuration, hundreds of thousands of TCP connections can be maintained on a single server.