I have a system which consists of two applications. Currently, two applications communicate using multiple ZeroMQ
PUB/SUB
patterns generated for each specific type of transmission. Sockets are programmed in C.
For example, AppX uses a SUB
formal-socket archetype for receiving an information struct
from AppY and uses another PUB
formal-socket archetype for transmitting raw bit blocks to AppY and same applies to AppY. It uses PUB/SUB
patterns for transmission and reception.
To be clear AppX and AppY perform the following communications:
AppX -> AppY :
- Raw bit blocks of 1 kbits
(continous),
- integer command (not continuous, depends on user)
AppY -> AppX :
Information struct
of 10kbits
(continuous)
The design target:
a) My goal is to use only one socket at each side for bidirectional communication in nonblocking mode.
b) I want two applications to process queued received packets without an excess delay.
c) I don't want AppX to crash after a crashed AppY.
Q1:
Would it be possible with ZeroMQ
?
Q2:
Can I use ROUTER/DEALER
or any other pattern for this job?
I have read the guide but I could not figure out some aspects.
Actually I'm not well experienced with ZeroMQ
. I would be pleased to hear about additional tips on this problem.
Q1:
yesQ2:
no, ZMQ_DEALER should be used by both AppX and AppY. See http://zguide.zeromq.org/c:asyncsrv. Notice ZMQ_ROUTER in this example just aim to distribute request from multi-client to different thread where ZMQ_DEALER do real work.A1:
Yes, this is possible inZeroMQ
ornanomsg
sort of toolsBoth the
ZeroMQ
and it's younger sisternanomsg
share the vision ofScaleable ( which you did not emphasise yet )
Formal ( hard-wired formal behaviour )
Communication ( yes, it's about this )
Pattern ( that are wisely carved and ready to re-use and combine as needed )
This said, if you prefer to have just one socket-pattern on each "side", then you have to choose such a Formal Pattern, that would leave you all the freedom from any hard-wired behaviour, so as to meet your goal.
So, a) "...only one" is doable -- by a solo of
zmq.PAIR
(which some parts of documentation flag as a still an experimental device) orNN.BUS
or a pair ofPUSH/PULL
if you step back from allowing just a single one ( which in fact does eliminate all the cool powers of the sharing of thezmq.Context()
instantiated IO-thread(s) for re-using the low-level IO-engine. If you spend a few minutes with examples referred to below, you will soon realise, that the very opposite policy is quite common and beneficial to the design targets, when one uses more, even many, patterns in a system architecture.The a) "...non-blocking" is doable, by stating proper directives
zmq.NOBLOCK
for respective.send() / .recv()
functions and by using fast, non-blocking.poll()
loops in your application design architecture.On b) "...without ... delay" is related to the very noted remark on application design architecture, as you may loose this just by relying on a poor selection and/or not possible tuning of the event-handler's internal timings and latency penalties. If you shape your design carefully, you might remain in a full control of the delay/latency your system will experience and not bacoming a victim of any framework's black-box event-loop, where you can nothing but wait for it's surprises on heavy system or traffic loads.
On c) "... X crash after a Y crashed" is doable on
{ ZeroMQ | nanomsg }-
grounds, by a carefull combination of non-blocking mode of all functions + by your design beeing able to handle exceptions in the situations it does not receive anyPOS_ACK
from the intended{ local | remote }-
functionality. In this very respect, it is fair to state, that some of the Formal Communication Patters do not have this very flexibility, due to some sort of a mandatory internal behaviour, that is "hard wired" internally, so a due care is to be taken in selecting a proper FCP-archetype for each such still scaleable but fault-resilient role.Q2:
No.The best next step:
You might feel interested in other
ZeroMQ
posts here and also do not miss the link to the book, referred there >>>