Tuan Hoang wrote:

> I'm running a distributed simulation and there is one server
> which opens a TCP socket, writes a message, and closes a socket to it's
> registered clients for every message that it processes.
> 
> With hundreds (maybe 1000s) of messages per second being processed by this
> server, will the server ever reach a point where it seems to block trying
> to create new sockets to deliver the new messages?  If so why?
> (A simple answer will suffice.)

If you exhaust the local port range, connect() will fail with EAGAIN
(Resource temporarily unavailable).

This can easily happen if you are creating client sockets rapidly. 
Bear in mind that ever connection will remain in the TIME_WAIT state
for some time after it has closed. While it remains in that state, the
source port cannot be re-used.

Possible solutions include:

a) increasing the number of ephemeral ports, with e.g.

        echo 1024 65535 > /proc/sys/net/ipv4/ip_local_port_range

Note that the above won't leave *any* unprivileged ports available for 
servers.

b) explicitly bind()ing the client sockets, managing the port numbers
yourself, and using setsockopt(SO_REUSEADDR) to allow a single source
port to be used for many connections.

You still have the restriction that you can't reuse a particular port
if the resulting connection would have the same ports and IP addresses
for both source and destination as an existing connection (including
one in the TIME_WAIT state).

-- 
Glynn Clements <[EMAIL PROTECTED]>
-
To unsubscribe from this list: send the line "unsubscribe linux-net" in
the body of a message to [EMAIL PROTECTED]

Reply via email to