4

I don't see my ZeroMQ PUSH/PULL socket pair behaving as documented (here and here):

When a ZMQ_PUSH socket enters the mute state due to having reached the high water mark for all downstream nodes, or if there are no downstream nodes at all, then any zmq_send(3) operations on the socket shall block until the mute state ends or at least one downstream node becomes available for sending; messages are not discarded.

The Java example below shows a scenario where I expect the second call to send to block, since I've set the send HWM to 1, I've already sent one message and no message has been received on the PULL socket. What I'm seeing is that the send completes, returning true (indicating the send was successful).

The idea is to apply back pressure to the data flowing through this PUSH/PULL pair. The send calls on the push side should block the thread if it's outpacing the PULL side. Can someone suggest how I can achieve this?

I built jzmq from the HEAD of the master branch and am running against version 3.2.4 of zmq installed from brew on a Mac (I saw the same behaviour against zmq version 4.0.5_2 also installed with brew, with jzmq built from the same source).

import org.zeromq.ZMQ;

public class Main {

    public static void main(String[] args) {

        ZMQ.Context context = ZMQ.context(1);

        ZMQ.Socket pullSocket = context.socket(ZMQ.PULL);
        pullSocket.setRcvHWM(1);
        pullSocket.bind("tcp://*:9944");

        ZMQ.Socket pushSocket = context.socket(ZMQ.PUSH);
        pushSocket.setSndHWM(1);
        pushSocket.connect("tcp://localhost:9944");

        boolean pushResult = pushSocket.send("a");
        // Expecting this call to block, but it delivers the message:
        pushResult = pushSocket.send("b");

        String message = new String(pullSocket.recv());
        message = new String(pullSocket.recv());
        // This third call does block, since only two message were pushed:
        message = new String(pullSocket.recv());

    }
}
Martin Dow
  • 5,273
  • 4
  • 30
  • 43
  • I agree this is really unexpected behaviour of PUSH/PULL.Have a look at High water mark socket settings and [this thread](http://stackoverflow.com/a/26424611/4312669). – sebkraemer Dec 08 '16 at 13:05
  • I am experiencing the same behavior. Will come back if I managed to solve it. – kaiya Dec 17 '20 at 09:28

0 Answers0