[zeromq-dev] Load balancing REQ/REP sockets

Brian Granger ellisonbg at gmail.com
Wed Mar 17 04:51:43 CET 2010


Hi,

REQ/REP sockets have a load balancing feature.  If you have 1 master
with a REQ socket that binds:

    ctx = zmq.Context()
    s = ctx.socket(zmq.REQ)
    s.bind('tcp://127.0.0.1:5555')

And multiple workers that connect REP sockets to the REQ:

    # Each worker does this.
    ctx = zmq.Context()
    s = ctx.socket(zmq.REP)
    s.connect('tcp://127.0.0.1:5555')

When the master does a send, the requests will be load balanced to all
connected workers.  That works fine.

But, a REQ socket cannot do another send until it gets back a reply
(by doing a recv).  So here is my question:

How can you actually get load balancing in practice if the REQ socket
in the master cannot issue another send
(to a different worker) until first worker has replied.  Another way
of putting this is I don't see how to get the multiple
workers handling requests *simultaneously*.  Am I missing something or
is this by design.

I can see how to accomplish this pattern with P2P sockets, but it
would require a much more complicated application logic to implement.

thoughts?

Cheers,

Brian

-- 
Brian E. Granger, Ph.D.
Assistant Professor of Physics
Cal Poly State University, San Luis Obispo
bgranger at calpoly.edu
ellisonbg at gmail.com



More information about the zeromq-dev mailing list