[zeromq-dev] Is Pub/Sub unreliable

Martin Sustrik sustrik at 250bpm.com
Wed Mar 10 14:38:50 CET 2010


gonzalo diethelm wrote:

> But now sender sleeps after binding to the PUB socket and before it
> starts sending messages. There are two cases happening here:
> 
> 1. If the sender sleeps any amount of ms above 100, the receiver gets
> all messages.
> 
> 2. If the sender sleeps, say, 50 ms, the receiver misses a few of the
> initial messages sent by sender.

That's because delay between two subsequent attempts to reconnect is set 
to 100ms. See src/config.hpp:

         //  Maximal wait time for a timer (milliseconds).
         max_timer_period = 100,

> If this is by design, that's fine; I could always add a small sleep time
> after binding to a PUB socket. But what I don't understand is this: why
> do I need any sleeping time at all, if the receiver started first and
> its SUB socket has been idling for a couple of seconds?
> 
> The only explanation I can find is that, although the SUB socket is
> ready, it still needs to do some processing when it is notified that the
> corresponding PUB socket came alive; while it is doing that processing,
> the sender has already sent some messages. Is this the case?

The problem is that you are dealing with completely asynchronous system 
(the network). You cannot expect anywthing will happen "immediately". 
Getting SUB socket notified about PUB socket being alive takes some 
time. In this case it's 100ms. You can lower the time needed by tweaking 
the value I've mentioned above, however, it'll never be instant.

Martin





More information about the zeromq-dev mailing list