Can reply be optional in ZeroMQ?

China☆狼群 提交于 2019-12-23 03:29:06

问题


I'm implementing a Lamport's distributed MUTEX algorithm in ZeroMQ.

Algorithm :

Requesting process

1 ) Pushing its request in its own queue (ordered by time stamps)
2 ) Sending a request to every node.
3 ) Waiting for replies from all other nodes.
4 ) If own request is at the head of its queue and all replies have been received, enter critical section.
5 ) Upon exiting the critical section, remove its request from the queue and send a release message to every process.

Other processes

1 ) After receiving a request, pushing the request in its own request queue (ordered by time stamps) and reply with a time stamp.
2 ) After receiving release message, remove the corresponding request from its own request queue.

I'm considering coding the solution in C or Java, but the core of the problem seems to be language-neutral.

In my problem, I have three message types, let's call them Request, Reply and Release. The Request/Reply messages fit well into REQ/REP pattern, but the Release message is one-way signal and does not need a reply. I could add an additional PUB/SUB pair, but then, in my understanding, I will not have the guarantee of FIFO delivery order in the system, because I would end up having two concurrent TCP connections (is this assumption right?).

I could make use of a basic non-constrained fullduplex channel. Another answer suggests using DEALER/ROUTER pair, but it seems like an overkill for such a simple problem. In docs, DEALER/ROUTER is described in Advanced Request-Reply Patterns chapter, and my problem doesn't seem to need an extreme solution.

How can my problem be solved?


回答1:


"Can reply be optional in ZeroMQ?"

Short version: Can.

just set properly .setsockopt( zmq.REQ_RELAXED, 1 )


Longer version:

There will be more issues yet to be solved for defined problem, if indeed distributed-system ought gain robustness. REQ/REP need not fall into a principally unsalvageable mutual-deadlock, as a distributed-FSA was shortcut with .REQ_RELAXED settings, yet ZeroMQ does not provide warranty for a message delivery. It is a best-effort delivery, so you need to implement a higher-level protocol handshaking, if in a need for a guaranteed message delivery. Setting .setsockopt( zmq.REQ_CORRELATE, 1 ) may help in this.



来源:https://stackoverflow.com/questions/49467333/can-reply-be-optional-in-zeromq

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!