zmq:可以将多个线程以简单的推-拉模式推入 [英] zmq: can multiple threads PUSH in a simple PUSH-PULL pattern
问题描述
我有两个过程:生产者,它通过 ZMQ 将消息推送到消费者以简单的点对点模式进行.生产者具有通过zmq send()
的几个内部线程.但是,0MQ的文档建议不要在线程之间共享套接字.
我必须使用单个线程发送吗?
假定对线程之间的发送顺序没有严格的要求,那么套接字是单向单工的事实是否允许多个线程在不引入锁的情况下使用它?
最简单的方法是在每个生产者线程上创建一个单独的PUSH套接字,并将所有这些套接字connect
都创建到使用者中的单个PULL套接字. /p>
指南中明确指出ZeroMQ套接字必须在单个线程上使用.我想说,违反此要求不是一个好主意,即使它看起来可行:在该库的下一版本中或某些特定平台上或某些特定负载情况下,事情可能会中断.因此,这太冒险了.
I have two processes: a producer which pushes messages via ZMQ to a consumer in a simple PULL-PUSH point-to-point pattern. The producer has several internal threads that send()
via zmq. However, 0MQ's docs suggest not to share sockets between threads.
Must I use a single thread to send?
Assuming there is no strict requirement for keeping the sending order between the threads, doesn't the fact that the socket is a one-directional simplex allow multiple threads to use it without introducing locks?
The easiest thing to do is to create a separate PUSH socket on each of producer's threads and connect
all these sockets to a single PULL socket in consumer.
It's explicitly stated in the guide that ZeroMQ sockets must be used on a single thread. I'd say that violating this requirement is not a good idea, even if it seems to work: things may break in the next version of the library or on some specific platform or in some specific load scenario. So, it's just too risky.
这篇关于zmq:可以将多个线程以简单的推-拉模式推入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!