The Actor Model

on

Watch Carl Hewitt himself explain the Actor Model (link here).

From DeepFriedCode:

The Actor Model uses message passing to send data directly to a single actor asynchronously. Every actor has a unique address to determine which actor should receive what message. A mailbox (an ordered queue) stores received messages in the actor.

Messages can be taken from the mailbox in any order. In most implementations, actors have a message processing procedure that will pattern match on the messages, similar to a case or switch statement, and pass the messages to the appropriate methods of the actors. If the message is unknown, then it is either silently discarded or creates an error depending on the implementation.

Actors can only send messages to other actors that they know about (i.e. actors they have addresses to). It could be an address that was sent in a message or an address of an actor it created.

Message delivery is not guaranteed. At most, messages are delivered once and possibly never get delivered. To ensure that a message reaches its destination you have to use an acknowledgment protocol between the two actors.

Like all types of dataflow, receiving a message triggers the activation of an actor. Execution happens concurrently.

Actors are referentially transparent (functional) per invocation. They can change their internal state but it does not take effect until the next activation. Effectively they pass their state out and back to themselves so that the next activation uses the updated state.

Local data is encapsulated inside actors. The only way to communicate with them is through messages. Internal data can not leak out unless it is specifically sent to other actors.

The Actor Model is similar to OOP except the methods do not return a value. Instead they send messages to return values.

A message is a form of indirect call. An actor never directly calls methods in other actors. In fact, they couldn’t even if they wanted to.

By removing direct calls, actors are able to work concurrently with other actors, essentially asynchronous objects.

Like objects, actors retain local state and can be created.

From Sravan Thokala:

actor

An actor is a computational entity that, in response to a message it receives, can concurrently.

  • Send a finite number of messages to other actors;
  • Create a finite number of new actors or
  • Designate the behavior to be used for the next message it receives.

Overview of Actor Model

  • The Actor model is an inherently concurrent model of programming.
  • Systems comprise of concurrent, autonomous entities, called actors, and messages.
  • Each actor has a unique, immutable name which is required to send a message to that actor.
  • An actor name cannot be guessed but may be communicated to other actors.
  • Each actor has its own mutable local state; actors do not share this local state with other actors–each actor is responsible for updating its own local state.
Advertisements

Subjectivity aside, leave a reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s