Actor model an approach to concurrency 1.0 (freiburg)

Post on 11-Jan-2017

25 Views

Category:

Software

1 Downloads

Preview:

Click to see full reader

Transcript

The Actor Model

1

An alternative approach to concurrency

Lorenzo Nicora Senior Consultant @ OpenCredo

@nicusX https://opencredo.com/author/lorenzo/

✓ (1973) Carl Hewitt: “A Universal Modular Actor Formalism for Artificial Intelligence”

2

A bit of History…

1973

2009

✓ (2009) Akka toolkit, Scala/Java✓ (1986) Ericsson: Erlang

Lorenzo Nicora Actor Model

According to Alan Kay, author of Smalltalk and inventor of the “Object-Orientation”:

3

The original idea of Object

An “Object”

✓ Is the basic unit of object-oriented system

✓ Has its own state

✓ Communicate with others

by sending and receiving messages*

* in Java, C++, C# (derived from Simula, not Smalltalk) Objects interact by invoking methods

1980

Lorenzo Nicora Actor Model

An “Actor” is a computational entity that, in response to a message it receives, can concurrently:

a) Send a finite number of messages to other actors

b) Create a finite number of new actors

c) Designate the behaviour to be used for the next message it receives. [implies a state]

4

The Actor

Actor

Actor

Actor

Mailbox Mailbox

Mailbox

Lorenzo Nicora Actor Model

Actors interacts only by messaging

Actors react to messages

5

Actors are Reactive

Lorenzo Nicora Actor Model

An Actor handles one message a timeNever concurrently

An Actor has a state State cannot be modified from outside the actor

6

Thread-safe

An Actor is inherently thread-safeNo Lock/Synchronisation on State

Lorenzo Nicora Actor Model

7

Supervision

Actors are created by Actors

Parent -> Child

Lorenzo Nicora Actor Model

8

Supervision

Failure Handling • If a Child throws an Exception, the Supervisor get notified • Supervision Strategy: e.g. relaunch, abandon…

Failure is always handled consistently

Parent = Supervisor

Lorenzo Nicora Actor Model

9

Lightweight

Actor is lightweight

Creating an Actor has little overhead beyond creating an Object

Lorenzo Nicora Actor Model

Non-blocking implementation of Request/Response pattern

with multiple downstream collaborators

10

Example: Non-blocking Request/Response

• One-Actor-per-Request pattern

• Enterprise Integration Patterns: ✴ Request/Reply ✴ Return Address ✴ Scatter-Gather, Aggregators ✴ Round-robin Message Router

Lorenzo Nicora Actor Model

11

Example: Non-blocking Request/Response

Lorenzo Nicora Actor Model

12

Example: Non-blocking Request/Response

Lorenzo Nicora Actor Model

13

Example: Non-blocking Request/Response

Lorenzo Nicora Actor Model

14

Example: Non-blocking Request/Response

Lorenzo Nicora Actor Model

15

Example: Non-blocking Request/Response

Lorenzo Nicora Actor Model

16

Example: Non-blocking Request/Response

Lorenzo Nicora Actor Model

17

Example: Non-blocking Request/Response

Lorenzo Nicora Actor Model

18

Example: Non-blocking Request/Response

Lorenzo Nicora Actor Model

19

Example: Non-blocking Request/Response

Lorenzo Nicora Actor Model

20

Example: Non-blocking Request/Response

Lorenzo Nicora Actor Model

21

Example: Non-blocking Request/Response

Lorenzo Nicora Actor Model

22

Conclusions

Actor model: an alternative approach to concurrency

Actors, Threads

+ Business logic implementation + inherently thread-safe

- A new programming paradigm - to learn

Lorenzo Nicora Actor Model

23Lorenzo Nicora Actor Model

top related