[erlang-questions] Re: testing asynchronous code

Ulf Wiger <>
Thu Apr 22 09:38:21 CEST 2010


Bernard Duggan wrote:
> To address the earlier question that lead to this, my understanding is
> that if you have the following message sending:
> 
> A -> B
> A -> C
> C -> B (dependant on message from A)
> 
> then the message from A to B /is/ guaranteed to arrive before the
> message from C.  Feel free to correct me on that though.

Although most conceivable implementations ought to give the
expected order, I am not aware of any explicit guarantee in
this case. Specifically, in the distributed case, I believe it
not to be true at all.

Imagine that A, B and C are all on different nodes. We can then
easily imagine the connection between node(A) and node(B) to be
significantly slower than the two others, or perhaps even temporarily
congested. In this case, a message could travel from A to C to B
faster than A->B.

This was in fact one of the things covered by Hans Svensson at the
Erlang Workshop in Freiburg 2007
(http://www.erlang.org/workshop/2007/proceedings/06svenss.ppt)

For now, one can make a distinction between inter-node messaging
semantics and intra-node semantics. When two local pids are
talking to each other, message delivery is atomic. This is not
true in the distributed case. Even inside a VM to day (with SMP)
exit signals are asynchronous, and there is good reason to make
normal message passing more asynchronous as well. This would
improve many-core scalability, but would have the effect that
the behaviour you mention can not be assumed to hold.

The one ordering guarantee that exists is that if P1 sends a
sequence of messages to P2, they will arrive in the same order
as they were sent.

(Unfortunately, Hans Svensson was able to devise a test with
two nodes forcing the disclaimer "...provided they arrive
at all")

BR,
Ulf W
-- 
Ulf Wiger
CTO, Erlang Solutions Ltd, formerly Erlang Training & Consulting Ltd
http://www.erlang-solutions.com
---------------------------------------------------

---------------------------------------------------

WE'VE CHANGED NAMES!

Since January 1st 2010 Erlang Training and Consulting Ltd. has become ERLANG SOLUTIONS LTD.

www.erlang-solutions.com



More information about the erlang-questions mailing list