[zeromq-dev] HMW not working? (DEALER - REP)

Krystian Samp samp.krystian at gmail.com
Wed Dec 24 00:32:06 CET 2014


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()


More information about the zeromq-dev mailing list