Note that there are some explanatory texts on larger screens.

plurals
  1. POZeroMQ PUB socket buffers all my out going data when it is connecting
    text
    copied!<p>I noticed that a zeromq PUB socket will buffers all outgoing data if it is connecting, for example</p> <pre><code>import zmq import time context = zmq.Context() # create a PUB socket pub = context.socket (zmq.PUB) pub.connect("tcp://127.0.0.1:5566") # push some message before connected # they should be dropped for i in range(5): pub.send('a message should not be dropped') time.sleep(1) # create a SUB socket sub = context.socket (zmq.SUB) sub.bind("tcp://127.0.0.1:5566") sub.setsockopt(zmq.SUBSCRIBE, "") time.sleep(1) # this is the only message we should see in SUB pub.send('hi') while True: print sub.recv() </code></pre> <p>The sub binds after those messages, they should be dropped, because PUB should drop messages if no one connected to it. But instead of dropping messages, it buffers all messages.</p> <pre><code>a message should not be dropped a message should not be dropped a message should not be dropped a message should not be dropped a message should not be dropped hi </code></pre> <p>As you can see, those "a message should not be dropped" are buffered by the socket, once it gets connected, it flush them to SUB socket. If I bind at the PUB socket, and connect at the SUB socket, then it works correctly.</p> <pre><code>import zmq import time context = zmq.Context() # create a PUB socket pub = context.socket (zmq.PUB) pub.bind("tcp://127.0.0.1:5566") # push some message before connected # they should be dropped for i in range(5): pub.send('a message should not be dropped') time.sleep(1) # create a SUB socket sub = context.socket (zmq.SUB) sub.connect("tcp://127.0.0.1:5566") sub.setsockopt(zmq.SUBSCRIBE, "") time.sleep(1) # this is the only message we should see in SUB pub.send('hi') while True: print repr(sub.recv()) </code></pre> <p>And you can only see the output</p> <pre><code>'hi' </code></pre> <p>This kind of strange behavior cause a problem, it buffers all data on a connecting socket, I have two servers, server A publishes data to server B</p> <pre><code>Server A -- publish --&gt; Server B </code></pre> <p>It works fine if server B gets online. But what if I start the Server A and do not start Server B?</p> <p>As the result, the connecting PUB socket on Server A keeps all those data, the memory usage gets higher and higher. </p> <p>Here is the problem, is this kind of behavior a bug or feature? If it is feature, where can I find a document that mentions this behavior? And how can I stop the connecting PUB socket buffers all data?</p> <p>Thanks.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload