Skip to content
Advertisement

Multiple parallel tcp connections

My (linux) server has two public IPs and I would like to make some parallel connections, to a same or different servers (my server acts as client program here; it just runs a C++ program that communicates with other servers to fetch some data).

Let’s suppose I want to stablish 100 parallel connections, is there any difference in performance or stability, from the point of view of the SO, between making 100 connections from a same IP, or 50 connections from the first IP, and another 50 conenctions from the second one?

In other words, is there any difference (is it safer) if I distribute the connections between the different available (local) IPs?

MAYBE RELATED: https://stackoverflow.com/a/3923785/1794803.

Advertisement

Answer

Outgoing TCP connections have also port numbers assigned with them. These are 16 bit numbers, resulting in 65.535 possible connections at one single point of time (port 0 has a special meaning). After dismantling a connection the TCP protocol requires the connection to stay in a special state TIME-WAIT (see http://www.tcpipguide.com/free/t_TCPOperationalOverviewandtheTCPFiniteStateMachineF-2.htm for a more complete description of the finite state machine). This is usually preconfigured with 60 seconds or so. With some extra tricks the period the source port ressource stays in TIME-WAIT can be significantly lowered. However, these two parameters in fact limit the number of connections at a time. All these restrictions apply to a single IP address. If you have n times IP addresses your TCP/IP stack is able to maintain n times many connections.

Be careful with potential NAT gateways between your client and the servers, if you run a huge number of parallel connections these routers’ NAT tables may or may not be able to deal with that many connections.

In general I am not sure if your general architecture suits your use case. There may be reasons your servers won’t allow only for a limited number of connections. Coding around these shaping mechanisms might just lead to a hare and tortoise race.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement