[erlang-questions] Message send guarantees
Thu Jan 26 00:06:05 CET 2017
Thanks Lukas, please see a couple of questions/comments below.
From: Lukas Larsson <lukas@REDACTED>
Sent: Wednesday, January 25, 2017 12:37 AM
On Wed, Jan 25, 2017 at 12:38 AM, Dmitry Kakurin <dima_kakurin@REDACTED<mailto:dima_kakurin@REDACTED>> wrote:
When I execute "pid ! msg" and it returns, what are the guarantees if pid and self are on the same node?
Can I assume that by the time it returns, msg is in the pid's queue? And as a result all messages sent to pid afterwards will be queued after msg?
No you cannot assume that. The message is considered "in transit" until the receiving process inspects it somehow.
What aspect of implementation can cause such reordering? Could you give an example how this could happen? Maybe I'll be able to artificially create conditions where it would not happen. Or work around it in some other way. Please see below why.
The reason I'm asking is because I need a guarantee of proper message ordering in the following scenario when all processes involved are local to a node:
1. A --msg1--> C (process A sends msg1 to process C)
2. A --msg2--> B
3. B --msg2--> C (process B simply proxies msg2 from A to C)
I need a guarantee that msg2 will always appear in C's queue after msg1.
You have to do this using messages or some other sync mechanism.
You are right, in general it's easy to devise a simple scheme for that.
Unfortunately I have a limitation. In my case A talks to C thru proxy B and would like to short-circuit the communication by getting rid of B and start talking to C directly. Process A needs to do that while messages thru B could be in flight. The limitation is that C is not aware of this proxy business, and cannot be changed (it's a regular GenServer that is not written by me).
With lack of cooperation from C I cannot think of a communication protocol to accomplish what I want.
Is there a way for processes A and B to observe C's queue in any way and derive some information about it to help me with my problem?
P.S. I've read the FAQ 10.8 and 10.9 :-)
Please add to the FAQ if you think that you can make it clearer on this point. https://github.com/matthiasl/Erlang-FAQ
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the erlang-questions