Concurrent connections

On this page 7

Concurrent connections are the number of client connections a server holds open at the same instant, whether those connections are actively transferring data, waiting for a request or idling under keep-alive. In Server performance work on servers, the figure describes simultaneous occupancy of server resources, which makes it a different measure from throughput or requests per second.

Every open connection consumes a file descriptor, kernel socket buffers, some application memory and, depending on the server architecture, a thread, a process or an entry in an event loop. The ceiling on concurrent connections is therefore set by whichever of these resources runs out first, and planning capacity means knowing which one that is.

How concurrent connections occupy server resources

A connection exists from the TCP three-way handshake until one side closes it, and the server must keep state for the whole of that lifetime. On a typical Linux host the kernel stores each socket with its send and receive buffers, which commonly range from a few kilobytes to several megabytes per socket when autotuning is active.

Above the kernel, the application decides how expensive a connection is. A thread-per-connection model dedicates a thread with its own stack to each client, while an event-driven model multiplexes thousands of sockets through readiness notification such as epoll on Linux or kqueue on BSD systems. The difference explains why the C10k problem was solved by changing architecture rather than by adding hardware.

The following table lists the resources that each open connection consumes and the usual limit that caps them.

ResourceTypical cost per connectionLimiting setting
File descriptorOne descriptorulimit -n, fs.file-max
Kernel socket buffersSeveral KB to several MBnet.ipv4.tcp_rmem, tcp_wmem
Worker thread or process256 KB to 8 MB of stackWorker pool size
TLS session stateTens of KBAvailable memory
Ephemeral port (outbound)One port per destination tupleip_local_port_range
Per-connection resources and their limits

Concurrent connections versus throughput and response time

Concurrency, throughput and latency are linked by Little’s law, which states that the average number of items in a system equals the arrival rate multiplied by the average time each item spends there. A server receiving 2,000 requests per second with an average response time of 50 ms therefore holds about 100 requests in flight at any moment.

Open connections usually exceed requests in flight, because HTTP keep-alive leaves idle connections open between requests. A site can show 20,000 concurrent connections while only a few hundred requests are being processed, and confusing the two numbers leads to badly sized worker pools.

The table below separates the related metrics that are often mixed up in capacity discussions.

MetricWhat it measuresTypical unit
Concurrent connectionsSockets open at one instantCount
Requests in flightRequests being processed nowCount
Requests per secondCompleted requests over timeRequests per second
ThroughputData or work delivered over timeMbit/s or transactions per second
Response timeDuration of one requestMilliseconds
Related server performance metrics

Server architectures and their connection ceilings

The architecture of the server software is the largest single factor in how many concurrent connections a host can sustain. Process-based and thread-based servers hit memory limits early, whereas asynchronous event loops keep idle connections cheap and shift the limit toward file descriptors and kernel memory.

A proxy layer changes the picture again. Placing an event-driven reverse proxy in front of a PHP worker pool lets the proxy absorb tens of thousands of slow or idle client connections while passing only active requests to a small, fixed number of workers.

This table compares common connection handling models and the ranges they reach on ordinary hardware; actual results depend on memory, request mix and tuning.

ModelExamplePractical concurrency rangeMain constraint
Process per connectionApache preforkHundredsMemory per process
Thread per connectionClassic Java servlet containersHundreds to low thousandsThread stacks and context switching
Event loopNginx, Node.js, HAProxyTens of thousands to millionsFile descriptors and kernel memory
Hybrid event plus workersApache event MPM, PHP-FPM behind a proxyThousands at the edgeSize of the backend pool
Connection handling models compared

Tuning and measuring concurrent connections

Raising the connection ceiling starts with the operating system. Administrators commonly increase the open file limit to 65,535 or higher, enlarge the listen backlog through net.core.somaxconn, and widen the ephemeral port range on hosts that open many outbound connections to upstream services.

Measurement should come from the server itself rather than from assumptions. Tools such as ss -s report socket states, web server status modules expose active, reading, writing and waiting counts, and load generators such as Apache JMeter or k6 model concurrency with virtual users. A test should increase concurrency in steps and record where tail latency starts to climb sharply.

The decision table below matches common situations with a recommended adjustment.

SituationRecommended actionReason
Errors about too many open filesRaise ulimit -n and the service file limitDescriptors are exhausted before memory
Many idle keep-alive socketsShorten the keep-alive timeoutFrees descriptors held by idle clients
Backend workers all busyQueue at the proxy, tune the pool sizePrevents resource saturation in the backend
Connection resets under burstsIncrease the listen backlogAbsorbs short arrival spikes
Ephemeral port exhaustionReuse upstream connectionsAvoids churning TIME_WAIT sockets
Decision guide for connection tuning

Limitations and common mistakes

A high connection count is not a goal in itself. Accepting more connections than the backend can serve only moves the bottleneck into a queue, where requests wait and response times grow without any gain in completed work.

  • Treating maximum concurrent connections as a measure of speed, when it only measures how many clients can wait at once.
  • Sizing a worker pool from total open connections instead of requests in flight.
  • Ignoring slow clients and slowloris-style attacks, which hold connections open with minimal traffic to exhaust limits.
  • Testing with a few clients that reuse connections and concluding that production traffic, with many short-lived connections and TLS handshakes, will behave the same.
  • Raising limits without checking memory, which can trigger the out-of-memory killer under peak load.

A plain-language summary

Think of a server as a restaurant. Concurrent connections are the number of tables occupied right now, whether the guests are eating, ordering or just sitting with an empty glass. Each table takes space and some attention from the staff, even when nothing is happening at it.

A restaurant can fill every table and still serve food slowly if the kitchen is too small. Servers work the same way: many open connections do not mean fast service. What matters is having enough room for guests and enough cooks for the orders that are actually being prepared.

An example from practice

An online retailer prepares for a seasonal sale on a server running Apache with the prefork model and PHP. During the previous sale the site stopped responding at roughly 400 concurrent connections, because each Apache process used about 60 MB of memory and the 32 GB host ran out of room. Most of those processes were simply holding idle keep-alive connections.

The operations team places Nginx in front as a reverse proxy, moves PHP to a pool of 80 PHP-FPM workers and raises the open file limit to 100,000. A k6 test with stepped virtual users shows the proxy holding about 25,000 concurrent connections while the workers process roughly 1,500 requests per second. During the sale, the 95th percentile response time stays under 300 ms, and memory use remains below half of the available capacity.