阻塞操作和 ZeroMQ
我正在设计一个分布式系统,其中单线程服务器进程执行 CPU 密集型操作。这些操作由 ZeroMQ 网络消息触发。
如果单线程进程正在执行 CPU 密集型工作,I/O(ZeroMQ 套接字)会阻塞吗?
谢谢!
I'm designing a distributed system in which a single-threaded server processes perform a CPU intensive operation. These operations are triggered by ZeroMQ network messages.
If the single-threaded process is performing the CPU intensive work, will the I/O (ZeroMQ sockets) block?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果没有消息可供阅读,您将阻止阅读消息。
如果未完成的消息数量超过 ZMQ_HWM,您将阻止发送(默认情况下没有限制,但对于您拥有的内存有一个实际限制),如果消息被简单地删除,它似乎取决于套接字类型(您当达到该限制时,在这种情况下不会阻塞)。
如果您不想在任何情况下阻塞,您可以指定标志 ZMQ_NOBLOCK - zmq_send/zmq_recv 在这些情况下将失败而不是阻塞。
You'll block on reading messages if there's no messages to read.
You'll block on sending if the number of outstanding messages exceeds ZMQ_HWM (default it has no limit, but there's a practical limit as to how much memory you have), It seems to depend on the socket type if messages are simply dropped(you won't block in that case) when that limit is reached.
You can specify the flag ZMQ_NOBLOCK if you don't want to block in any of the cases - zmq_send/zmq_recv will fail instead of block in those cases.