[erlang-questions] clarify: order of messages
Mon Nov 19 13:56:27 CET 2007
> On Sun, Nov 18, 2007 at 10:55:35AM -0800, Zvi wrote:
>> Same processes on the same node?
>> Will be this a case when processes are on different nodes?
> If the same process (only one) sends two messages one after the other
> (Msg1 and Ms2, respectively) to another process, then those two
> messages are going to be received in the same order as they have been
> sent, i.e. Msg1 first and then Msg2. And this does not depend on the
> fact that the two processes are running on different nodes (since I'm
> quite sure that message passing among remote nodes is handled using
> TCP sockets, so the *order* of transmission should be preserved...)
> Or, at least, I hope it works so ;-)
With the current Erlang distribution mechanism messages in transit may
when two nodes are disconnected (e.g., if the sending and receiving
processes are on different nodes). Later, if the nodes are reconnected,
communication may flow normally again but the dropped messages may not
have been resent.
Thus in the example the receiving process may actually only receive the
second message (Msg2) in its queue, and never see Msg1.
It is guaranteed (we hope!) that Msg1 can never be added to the message
of the receiving process after Msg2 has been added.
For clarification see for instance Hans Svensson's slides
at the Erlang Workshop
or the paper (http://www.cs.chalmers.se/~hanssv/doc/ew07-dist.pdf).
In general communication is order preserving, but messages may be
dropped. Use monitors or links to guard against this possibility if your
protocol cannot cope with dropped messages.
More information about the erlang-questions