cra*_*kar 5 python tornado event-loop zeromq poller
设计明智和性能明智哪种方法建议用于处理多个Zeromq插座,为什么?
ZeroMQ使用的Tornado的IOLoop是否真的比使用while循环中的Poller处理多个套接字的CPU少?
如果您在问题中添加自己的观察/分析,那就太好了。
我认为性能上没有任何区别,但设计上有区别。
如果是轮询器
您注册要轮询的套接字,然后用于if blocks
识别和使用每个套接字。
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 ....
Run Code Online (Sandbox Code Playgroud)
在事件循环的情况下
,但是当您处理多个套接字时,使用事件循环非常优雅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)
Run Code Online (Sandbox Code Playgroud)
从第二个示例中您可以注意到,if 块已被删除。您可以在其他地方编写套接字消息传递操作,并在套接字准备就绪时注册回调方法。In this case on_recv()
我希望这能澄清你的问题。
归档时间: |
|
查看次数: |
2551 次 |
最近记录: |