Can ZeroMQ provide grounds for a bidirectional non-blocking asynchronous transmission?
Asked Answered
R

2

1

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.

Richel answered 22/6, 2016 at 13:1 Comment(2)
This question is not about C, or sockets etc. so much as it is about algorithm design. Not a good fit for this forum. Try the link, it is to programmers stack exchange.Bari
thank you, i will try the link you provided.Richel
A
1

A1: Yes, this is possible in ZeroMQ or nanomsg sort of tools

Both the ZeroMQ and it's younger sister nanomsg share the vision of
Scaleable ( 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) or NN.BUS or a pair of PUSH/PULL if you step back from allowing just a single one ( which in fact does eliminate all the cool powers of the sharing of the zmq.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 any POS_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 >>>

Asbestos answered 24/6, 2016 at 12:24 Comment(1)
thank you very much for your help. i will spend time with it and see if i can handle it. thanks again.Richel
S
0

Q1: yes
Q2: 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.

Specification answered 2/6, 2017 at 9:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.