[erlang-questions] Message send guarantees
Thu Jan 26 14:29:50 CET 2017
On Wed, Jan 25, 2017 at 12:38 AM, Dmitry Kakurin
> 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?
> 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.
This cannot be guaranteed
In the absence of an error you can assume the following:
That sequences of messages between pairs of processes are ordered (ie they
arrive in the same order they were sent)
You will never know if messages are processed by the destination process
Note I said "in the absence of an error" - to take care of the error case
we use links - links tell you if the linked processes have crashed,
Even if a message arrives at a process you will never know, you will also never
know if the processing it triggered worked - if you want to know send a message
back and wait for it.
If you want to know if a process works send it a message asking it to do
something, wait for a reply and check the reply is OK.
All this will tell you is that the process WAS working they last time you
asked it - and NOT that it IS working now.
Also remember that messages take time to propagate - and processes
take time to do
In your A -> B followed by B->C B might take a long time between relaying the
messages (due to garbage collection, or something weird)
The above behaviour does not break any laws of physics - ie messages
take time, causality is obeyed, these is no spooky action at a distance etc.
> P.S. I've read the FAQ 10.8 and 10.9 :-)
> Thank you, Dmitry.
> erlang-questions mailing list
More information about the erlang-questions