How Arbiters from the actor model are implemented in Erlang?
Asked Answered
F

1

5

I know that Erlang uses Actor model to support concurrency and Erlang processes are the same as Actors: they send messages, immutable and so on. But according to Carl Hewitt one important thing in the Actor Model is indeterminism and Arbiters (Given an arbiter, you can have multiple inputs (e.g. I0 and I1) into the arbiter at the same time, but only one of the possible outcomes (e.g. O0 or O1) will come out on the other end).

So, I'm interesting how does Erlang implemented this concept? And what is used in the role of Arbiters in the Erlang concurrency model/actor model implementation?

Fader answered 8/11, 2016 at 23:23 Comment(0)
L
10

This gets pretty deeply philosophical (see e.g. https://en.wikipedia.org/wiki/Indeterminacy_in_concurrent_computation), but as far as I can tell, he's saying that in the Actor Model, whenever an actor has multiple inputs, there's a magic box that decides the ordering of the incoming messages any way it wants to, even if it means delaying some of the messages for an arbitrarily long (but bounded) time. I.e., you can never rely on any particular order or time for receiving parallel messages, even if the program structure seems to favour a certain arrival order. (Note that this is a theoretical concept for reasoning about actor programs - you wouldn't try to make a system unnecessarily random in practice, except for testing purposes.)

The semantics of Erlang message passing say pretty much the same thing: whenever two processes send a message each to a third process, and there is no ordering constraint on the individual send events, you can never rely on which message will end up first in the receiver's mailbox. They could be arbitrarily delayed, even if all processes run within the same Erlang VM. Again, this is about what guarantees you get as a programmer (none), not about making the Erlang VM insert random delays. (Random delays can be introduced naturally by other things, such as OS-level pauses for page faults.)

Labradorite answered 9/11, 2016 at 16:40 Comment(4)
In practice you see the messages in the order they arrive at the process.Courbevoie
Yes, but arrival order is unpredictable even in Erlang, if senders are on different scheduler threads. The send operations could finish in one order (wallclock time) but the messages may still arrive in swapped order at the receiver's mailbox.Labradorite
I'm no expert but I don't read Hewitt's marks as any 'magic boxes' present, on the contrary I kind of logically perceive that arrival times are uncertain to a degree because 'the program' cannot guarantee the order of delivery (or delivery itself even) due to the processing time of 'the system' e.g. network, cpu, I/O circuitry? So the actual processing time seems causal to indeterminism? I might not understand the abstraction of an Arbiter in a programming language (like Erlang) though, could you elaborate?Paradrop
@HeddevanderHeide My interpretation is that Arbiters are a purely theoretical device which are included in order to have a complete description of what is happening when you have more than one message going to the same receiver. For example, to be able to replay a scenario, you'd need to include the decisions made by the arbiters at each execution step where there was a choice of messages. The decisions could still be random, but replayable, as given by a PRNG with a specific seed.Labradorite

© 2022 - 2024 — McMap. All rights reserved.