Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Please explain Zeromq eventloop

Tags:

zeromq

How is different from multiplexing several sockets via a POLLIN?

while True:
    socks = dict(poller.poll())

    if socks.get(control_receiver) == zmq.POLLIN:
        ...

    if socks.get(work_receiver) == zmq.POLLIN:
        ...

How can it make listener threads more reliable and easier to handle?


Background: I am rolling my own API server and wondering how to make the controller (the part that receives the requests from external source and control signals from the workers)

like image 429
Jesvin Jose Avatar asked Feb 22 '23 20:02

Jesvin Jose


1 Answers

ØMQ Poller can be used to serve and communicate with multiple sockets.

How ever, with ØMQ Poller, you end up with explicit blocks (under if loop) for handling the sockets. Each socket registered with ØMQ Poller has to have an explicit “if block” to handle it.

This becomes unwieldy as you start writing bigger programs. I would like to add - "a bit ugly"

With Event Loops, this becomes more streamlined as you can register callbacks to receive and send data and you can structure your callback else where.

I have following examples from the tutorial that I am writing.

  1. http://learning-0mq-with-pyzmq.readthedocs.org/en/latest/pyzmq/multisocket/zmqpoller.html
  2. http://learning-0mq-with-pyzmq.readthedocs.org/en/latest/pyzmq/multisocket/tornadoeventloop.html

Others can add on to this understanding or correct it.

like image 64
pyfunc Avatar answered Mar 05 '23 20:03

pyfunc