[zeromq-dev] REQ / REP and inproc sockets

Martin Sustrik sustrik at 250bpm.com
Thu Aug 26 15:21:47 CEST 2010


Hi Gonzalo,

>> And yes, I am an ass.

The introspection was fun to read :)

> On this high note, allow me two more questions.
>
> 1. I use a PUB socket (connects) in my server to publish every five
> seconds a heartbeat. From a monitor process I use a SUB socket (binds)
> to receive these heartbeats and show them on the console. The weird
> thing is this: if I start the server and leave it running for one
> minute, it shows it has sent 12 messages over the PUB socket. After that
> minute, when I bring up the console, it prints right away the 12
> heartbeat messages, and then it goes onto printing the heartbeat
> received every five seconds. But I understood the PUB socket operated as
> a radio, without saving for later any messages already sent over them.
> How is the monitor getting those 12 messages, sent before it was
> running? Am I going nuts?

There's still a transient buffer between the PUB and SUB socket so that 
random jitter on the line doesn't disrupt the transmission.

For heartbeats it would make sense to set the buffer size to 1 message 
(ZMQ_HWM option), so that at any point of time only 1 heartbeat is buffered.

> 2. What does everyone think about the possibility of compiling 0MQ with
> a flag, or maybe passing the socket a setsockopt flag at runtime, so
> that it will check that the socket is being used from the same thread as
> where it was created from? This could help debugging weird looking
> problems, like the one I had been experiencing today.

The latest changes on the trunk are the "socket migration between 
threads" code. Thus it will be possible to move your socket from thread 
A to thread B. That makes implementing the check impossible.

Martin




More information about the zeromq-dev mailing list