问题描述
如果您使用 PUSH 套接字,您会发现第一个连接的 PULL 套接字将获取不公平的消息份额.只有在所有 PULL 套接字都成功连接时才会发生消息的准确轮换,这可能需要几毫秒.作为 PUSH/PULL 的替代方案,对于较低的数据速率,请考虑使用 ROUTER/DEALER 和负载平衡模式.
因此,在 PUSH/PULL 中进行同步的一种方法是使用负载平衡模式.
So one way to do sync in PUSH/PULL is using the load balancing pattern.
对于下面这个特定的情况,我想知道是否还有另一种方式来进行同步:
For this specific case below, I wonder whether there is another way to do sync:
我可以将 worker 中的 PULL 端点设置为阻塞,直到连接成功建立,然后通过 worker 的 PULL 端点向sink"发送特殊消息.'sink'收到#worker的特殊消息后,'sink'向'ventilator'发送带有REQ-REP的消息,通知所有worker准备就绪.呼吸机"开始向工人分配工作.可靠吗?
I could set the PULL endpoint in worker to block until the connection successfully setup, and then send a special message via worker's PULL endpoint to 'sink'. After 'sink' receives #worker's special messages, 'sink' sends a message with REQ-REP to 'ventilator' to notify that all workers ready. 'ventilator' starts to distribute jobs to workers.Is it reliable?
图片来自这里
推荐答案
是的,只要 Sink
知道在告诉 之前要等待多少
表示可以开始发送消息了.如果 Workers
>VentilatorWorkers
在 Sink
连接之前启动,那么来自 Workers
的特殊消息是否能通过,但您可以通过让它们继续发送特殊消息直到他们开始从 Ventilator
获取数据.如果你这样做,Sink
当然会简单地忽略它收到的任何重复.
Yes, so long as the Sink
knows how many Workers
to wait for before telling the Ventilator
that it's OK to start sending messages. There's the question of whether the special messages from the Workers
get through if they start up before the Sink
connects - but you could solve that by having them keep sending their special message until they start getting data from the Ventilator
. If you do this, the Sink
would of course simply ignore any duplicates it receives.
当然,这与 Workers
与 Ventilator
的实时工作连接并不完全相同,但这本身可能会发送特殊的无用消息Workers
收到.当他们收到其中一个时,他们就可以开始向 Sink
发送特殊消息.
Of course, that's not quite the same as the Workers
having a live, working connection to the Ventilator
, but that could itself be sending out special do-nothing messages that the Workers
receive. When they receive one of those that's when they can start sending a special message to the Sink
.
这篇关于在 ZeroMQ 中进行 PULL-PUSH 同步的另一种可靠方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!