|
|
To be or not
to be -
that is the question.
(the actors model)
Paul Mackay
pjm2@doc.ic.ac.uk
All the world's a stage,
And all the men and women are merely players;
They have their exits and entrances;
And one man in his time plays many parts,
His acts being seven ages.
[As You Like It, II.vii]
Introduction
The title above is one of the most
famous quotes ever spoken by many actors throughout the years. However,
this essay is not about the traditional actors of film and stage,
but about actors as a computing paradigm, as distinct from other paradigms
such as imperative programming (e.g. Pascal), or object-orientated programming
(e.g. C++). This essay attempts to describe what actors are and how they
operate as a model. Describing the model as actors is appropriate, in the
context of the quote by Shakespeare above.
The Actor Unit
So, to take the basic unit of the
model, a single actor. An actor is an agent or unit of code which can perform
three distinct actions:
- Send communications to other actors.
- Define a new behaviour for itself, which may be the same
or different to its previous behaviour.
- Create new actors.
These actions will only be performed
upon receiving a communication. When this occurs, the receiving actor must
specify its new behaviour, but depending on its defined behaviour it
may or may not perform the other possible actions. Being able to create
new actors, called customers, provides a very dynamic
model which enhances its ability to respond to changes to the environment
and fully exploit the resources available. This can be especially valuable
in the environment of a parallel computer.
The diagram illustrates the three actions
an actor may perform.
[G. Agha. Actors: A Model of Concurrent Composition
in Distributed Systems. Page 26]
Concurrent Operation
Actors were developed as a model
for use with parallel systems. The key requirement for parallel systems
is that processes can be allocated concurrently to different processors.
The idea behind actors is that the model deals with allocation in the underlying
architecture (i.e. giving processes to processors), allowing the programmer to concentrate on optimising the parallel
nature of the program. Actor languages avoid the assignment statements,
and instead use actor replacement. This means actors can store history-sensitive
information, and also operate concurrently where there is no data dependency.
The model of actors is concurrent in two ways. All actors have the potential
to operate concurrently with each other, and all distinct operations within
an actor can execute concurrently.
Actor Communication
Actors communicate using message
passing only, and all communication is asynchronous. This means an actor
may send a message to another actor and continue executing, without waiting
for the message to be received. This system is made possible by the use
of mailboxes. Each actor has a mail address, and associated with this address
is a mail queue. An actor may be described by its behaviour and its mail
address. An actor’s acquaintances are defined as the mail addresses of
other actors it knows.
An actor may know a mail address because:
- It has always known the address.
- It received the address within a communication from another
actor.
- It created the address as part of creating another actor.
This ability to pass around mail
addresses to any other actors within the system enhances the dynamic nature
of the actor model.
The Actor System
An actor system may be categorised
by the actors within it and the set of tasks to be carried out. A task
will cause the system to carry out computation. It includes a unique tag,
a target mail address and a communication to send to that address containing
information for the target actor to carry out the request. An event is
defined as the creation of a new task.
For an actor system to interact
with the outside world, it must include two types of special actors. A
receptionist is an actor which may receive communications from outside
the system. An external actor is one which is not present within the system
but its address is known to one or more actors within the system, allowing
them to send communications elsewhere.
Built-in actors are used to complete
a computation. They represent primitive data types and simple operations.
For example, an actor representing an integer would, upon receiving a communication,
just reply with itself. An integer could even be defined to receive a request
giving the instruction to add itself to another integer, and it would reply
with the addition result.
Two important facts about the mail
system in the theoretical actor model are that mail arrives in a random,
non-deterministic order, and that mail delivery is guaranteed. The first
point backs up the asynchronous nature of the actor model. A system which
is so deeply concurrent cannot afford the performance degradation in having
ordered communication arrival and subsequent execution. The second point
ensures that the system can be guaranteed to execute all tasks eventually,
even when one task may cause infinite execution. All other tasks will at
some stage be evaluated. This deals with several important issues in parallel
computing. The problem of divergence (an infinite loop) can be interrupted
if required, because an actor will eventually accept another message from
elsewhere, which could halt the process. Deadlock can be detected and corrected
by external actors outside the problem area. Actors are totally contained,
and are only accessed by sending a message. In this way mutual exclusion
may be maintained. An actor may act as a buffer until the resource is free.
An Actor Language
An actor language program will consist
of only a few basic constructs. From these a whole system may be defined:
- Behaviour definitions which describe the actors.
- ‘New’ expressions which create actors.
- ‘Send’ commands which create tasks.
- A 'receptionist' declaration or list.
- An 'external' declaration or list.
Conclusion
This shows how simple the actor
model is, and yet because of its reliance on message passing and concurrency
it is also a powerful and elegant model for certain applications.
References:
G. Agha. Actors: A Model of Concurrent Computation in
Distributed Systems. MIT Press, Cambridge, Mass., 1986
Legendary Quotations. Harper Collins Publishers, Glasgow,
1995
|