[zeromq-dev] Even more fun with accept
Martin Sustrik
sustrik at fastmq.com
Mon May 4 09:57:54 CEST 2009
Hi all,
Let me summarise the scenarios we've encountered here:
1. A port is used by service A, then service B tries to use the same port.
2. Service requires N file descriptors to work properly (say if
component gets input through one connection and sends output to a
different connection, it needs 2 file descriptors), however, the max
limit for descriptors is set to less than N.
3. Service that is handling arbitrary number of clients (like a web
server). During the peak period number of clients trying to connect to
the service exceeds the limit for file descriptors.
I would argue that 1. and 2. are caused by misconfiguration of the
system and thus no auto-recovery should be even attempted, rather the
system should fail and notify admin about the problem in the
configuration. (Actually, once we have all the configuration centralised
in zmq_server, warning about the errors like 1 and 2 can be displayed
during the configuration of the system, long before any components are
started.)
This leaves us with case 3 which should be handled in a decent way -
there should be no failures in this case.
My idea would be that admin sets the fd limit and 0MQ should work as
smooth as possible within the bounds of the limit. Thus:
1. If the limit is exceeded, server should kill new clients rather then
let them hang.
2. Exceeding the limit should not result in excessive resource (CPU,
bandwidth etc.) consumption.
3. Once the number of clients drops below the limit, server should start
accepting new connections with no or little delay.
The algorithm I've outlined last week kind of meets these needs,
however, it still has few obscure spots. For example: There are two
servers listening for new connections in an application. Once the fd
limit is reached one of them fails to accept and closes the listening
socket to purge the connection backlog (so that clients don't hang).
Then it tries to reopen the listening socket but it fails as the other
service have accepted a new connection in the meantime and thus depleted
the fd pool again. At that point there's nothing to do but to set up a
timer and retry to open the listening socket after a while. In the
meantime there may be some fds freed and immediately re-used by the
other service. Thus it's pretty likely that once the timer expires, the
fd limit is exceeded and listener socket cannot be open. Etc. In short,
when there's a congestion involved one service can completely block out
another service.
Martin
Pieter Hintjens wrote:
> On Fri, May 1, 2009 at 6:18 PM, Dhammika Pathirana <dhammika at gmail.com> wrote:
>
>> I was referring to the possibility of another application rebinding
>> server port and impersonating the server.
>
> Yes, that was clear I think. This is possible only if the server
> actually stops and then before it restarts, another application opens
> the same listening port. This is not the scenario we have here.
>
> One strategy to prevent bogus servers occupying ports is to use ports
> below 4096 (on Unix systems) so that superuser access is needed to
> open the port.
>
> -Pieter
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
More information about the zeromq-dev
mailing list