python - ZeroMQ PUB socket buffers all my out going data when it is connecting -



python - ZeroMQ PUB socket buffers all my out going data when it is connecting -

i noticed zeromq pub socket buffers outgoing info if connecting, example

import zmq import time context = zmq.context() # create pub socket pub = context.socket (zmq.pub) pub.connect("tcp://127.0.0.1:5566") # force message before connected # should dropped in range(5): pub.send('a message should not dropped') time.sleep(1) # create sub socket sub = context.socket (zmq.sub) sub.bind("tcp://127.0.0.1:5566") sub.setsockopt(zmq.subscribe, "") time.sleep(1) # message should see in sub pub.send('hi') while true: print sub.recv()

the sub binds after messages, should dropped, because pub should drop messages if no 1 connected it. instead of dropping messages, buffers messages.

a message should not dropped message should not dropped message should not dropped message should not dropped message should not dropped hi

as can see, "a message should not dropped" buffered socket, 1 time gets connected, flush them sub socket. if bind @ pub socket, , connect @ sub socket, works correctly.

import zmq import time context = zmq.context() # create pub socket pub = context.socket (zmq.pub) pub.bind("tcp://127.0.0.1:5566") # force message before connected # should dropped in range(5): pub.send('a message should not dropped') time.sleep(1) # create sub socket sub = context.socket (zmq.sub) sub.connect("tcp://127.0.0.1:5566") sub.setsockopt(zmq.subscribe, "") time.sleep(1) # message should see in sub pub.send('hi') while true: print repr(sub.recv())

and can see output

'hi'

this kind of unusual behavior cause problem, buffers info on connecting socket, have 2 servers, server publishes info server b

server -- publish --> server b

it works fine if server b gets online. if start server , not start server b?

as result, connecting pub socket on server keeps data, memory usage gets higher , higher.

here problem, kind of behavior bug or feature? if feature, can find document mentions behavior? , how can stop connecting pub socket buffers data?

thanks.

whether socket blocks or drops messages depends on socket type described in zmq::socket documentation (emphasis below mine):

zmq::hwm: retrieve high water mark

the zmq::hwm alternative shall retrieve high water mark specified socket. high water mark hard limit on maximum number of outstanding messages 0mq shall queue in memory single peer specified socket communicating with.

if limit has been reached socket shall come in exceptional state , depending on socket type, 0mq shall take appropriate action such blocking or dropping sent messages. refer individual socket descriptions in zmq::socket details on exact action taken each socket type.

the default zmq::hwm value of 0 means “no limit”.

you can see if block or drop looking through documentation socket type zmq::hwm alternative action either block or drop.

the action zmq::pub drop, if not dropping should check hwm (high water mark) value , heed warning the default zmq::hwm value of 0 means “no limit”, meaning not come in exceptional state until scheme runs out of memory (at point don't know how behaves).

python zeromq pyzmq

Comments

Popular posts from this blog

delphi - blogger via idHTTP : error 400 bad request -

c++ - compiler errors when initializing EXPECT_CALL with function which has program_options::variables_map as parameter -

How do I check if an insert was successful with MySQLdb in Python? -