The kernel has a pair of internal buffers for each socket. In order for the sender to block, all the following buffers have to be full*: 1) the receiver's zmq socket queue (as per your HWM setting); 2) the receivers's TCP socket buffer; 3) the sender's TCP socket buffer; 4) the sender's zmq socket buffer.
*: the sender may temporarily block even if they are not full, such as when it is sending faster than the network can deliver the messages (in other words, only 3 and 4 are strictly required). André > On Dec 23, 2014, at 6:32 PM, Krystian Samp <[email protected]> wrote: > > Hello everyone, > > I’m using ubuntu (via docker), zeromq version 4.0.5, and pyzmq version > 14.0.1-1build2. > > I'm having a DEALER - REP connection where both sides have hwm set to 2. The > code behind REP connects to DEALER and waits 5 seconds. The code behind > DEALER sends 100 messages as rapidly as possible. I'd expect that DEALER > first sends 2 messages and blocks (because of hwm and because REP is not > actively receiving messages), but instead all 100 messages are sent > immediately. Is this a bug? or a normal behaviour? I'd like to send only N > messages to each connected REP. > > Thanks, > ks > > Here's the example demonstrating the above behaviour: > > import zmq > import threading > > def create_server(): > ctx = zmq.Context.instance() > socket = ctx.socket( zmq.DEALER ) > #socket.set_hwm( 2 ) > socket.setsockopt( zmq.SNDHWM, 2 ) > socket.setsockopt( zmq.RCVHWM, 2 ) > > socket.bind( "tcp://*:5558" ) > > server = { > "ctx": ctx, > "socket": socket, > } > return server > > def create_client(): > ctx = zmq.Context.instance() > socket = ctx.socket( zmq.REP ) > #socket.set_hwm( 2 ) > socket.setsockopt( zmq.SNDHWM, 2 ) > socket.setsockopt( zmq.RCVHWM, 2 ) > socket.connect( "tcp://127.0.0.1:5558" ) > client = { > "ctx": ctx, > "socket": socket, > } > return client > > def server_thread(): > server = create_server() > for i in range( 100 ): > server[ "socket" ].send_multipart( [ "", "krychu" ] ) > print( "+ server sent, %s" % i ) > > def client_thread(): > client = create_client() > sleep( 5 ) > > # > ------------------------------------------------------------------------------ > s = threading.Thread( target = server_thread ) > c = threading.Thread( target = client_thread ) > > s.start() > c.start() > _______________________________________________ > zeromq-dev mailing list > [email protected] > http://lists.zeromq.org/mailman/listinfo/zeromq-dev _______________________________________________ zeromq-dev mailing list [email protected] http://lists.zeromq.org/mailman/listinfo/zeromq-dev
