pythontornadozeromqevent-looppoller

ZeroMQ Poller vs Tornados EventLoop


Design wise and performance wise which approach is recommended for handling multiple Zeromq sockets and why ?

Is it true that Tornado's IOLoop used by ZeroMQ hogs less CPU than the Poller used in a while loop for handling multiple sockets ?


Solution

  • It would be nice if you add your own observation / analysis to your question.

    I don't think there is any difference in performance but there is a difference in design.

    In case of poller

    You register your sockets to be polled and then you use if blocks to identify and work with each socket.

    while should_continue:
            socks = dict(poller.poll())
            if socket_pull in socks and socks[socket_pull] == zmq.POLLIN:
                Work_on_socket_pull ....
    
            if socket_sub in socks and socks[socket_sub] == zmq.POLLIN:
                 Work_on_socket_sub ....
    

    In case of eventloop But using event loop is quite elegant when you are handling multiple sockets since you register callbacks.

    stream_pull = zmqstream.ZMQStream(socket_pull)
    stream_pull.on_recv(getcommand)
    
    stream_sub = zmqstream.ZMQStream(socket_sub)
    stream_sub.on_recv(process_message)
    

    As you can notice from the second example, the if blocks are removed. You write your socket messaging operation else where and you register your callback methods when socket is ready. In this case on_recv()

    I hope that clarifies your question.