[zeromq-dev] some question about the eventloop in py-zmq

MinRK benjaminrk at gmail.com
Mon Oct 31 16:50:24 CET 2011


On Mon, Oct 31, 2011 at 01:03, Sijia Xu <xsj.guagua at gmail.com> wrote:

> Hi all:
>
> I used to use Tornado to build TCP-server, it does a good job. recently i
> consider using zeromq to implement a tcp-sever cluster, so I read the guild
> book and the py-zmq source code, since i am really a newbie in zeromq, i
> got some questions about py-zmq:
>
> 1. I notice the ioloop in py-zmp-eventloop is similar to tornado's ioloop.
> the main difference is  the poll function in py-zmp-eventloop support the
> zmq socket and zmq-eventloop also use the zmqstream encapsulate the zmq
> socket. but i  notice the function in zmqstream(etc,on_receive,on_send)
>

Yes, we use the tornado ioloop, slightly modified (the diff is quite small)
to use zmq.poll.

You can read a quick summary of using the zmqstream/ioloop objects here:
http://zeromq.github.com/pyzmq/eventloop.html


>
> do not manage a inner rece/send buffer which can be found in tornado's
> iostream. basing on my understanding about zerpmq , I think it maybe manged
> by zmq-socket itself.  but in zmq-ioloop , the start function just pick the
> ready fd-handle pairs return by Poller.poll() and start the flowering  loop
> to call each fd handle once.
>

There are two levels of 'buffer' at work in the zmqstream - one is the real
zeromq buffer, which actually handles
sending/receiving over the wire.  The second is a simple Python Queue that
is loaded by the stream.send methods.  This is just a waiting list for
messages that should go out when the socket is ready to send.  In many
cases, it will never have more than one message.


>
> since a single zmq-socket usually represent many native fd in OS,
> if several event occur on one zmq-socket, each loop in start function only
> can deal with one of that, it would seems less efficient.
>

I'm not sure what you mean by 'many native fd' here.  A socket is a single
poll item, and can be polled for in/out/err events. It is true that only
one event (technically one of each kind, if they exist) is handled per
socket per loop iteration.  This is not uncommon, as it prevents a busy
socket from starving other sockets in the loop, and is
in fact the pattern followed in many zguide examples.


>
> 2. it seems the core codes in py-zmq have being compiling as the DLL, is
> there some way to see this source code?
>

As Robert pointed out, GitHub is the place to see our sourcecode:
https://github.com/zeromq/pyzmq

-MinRK


>
>
>
> best regard
>
> sjXu
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20111031/ddbc182e/attachment.htm>


More information about the zeromq-dev mailing list