actor model an approach to concurrency 1.0 (freiburg)

23
The Actor Model 1 An alternative approach to concurrency Lorenzo Nicora Senior Consultant @ OpenCredo @nicusX https://opencredo.com/author/lorenzo/

Upload: scott-speights

Post on 11-Jan-2017

25 views

Category:

Software


1 download

TRANSCRIPT

Page 1: Actor model   an approach to concurrency 1.0 (freiburg)

The Actor Model

1

An alternative approach to concurrency

Lorenzo Nicora Senior Consultant @ OpenCredo

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

Page 2: Actor model   an approach to concurrency 1.0 (freiburg)

✓ (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

Page 3: Actor model   an approach to concurrency 1.0 (freiburg)

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

Page 4: Actor model   an approach to concurrency 1.0 (freiburg)

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

Page 5: Actor model   an approach to concurrency 1.0 (freiburg)

Actors interacts only by messaging

Actors react to messages

5

Actors are Reactive

Lorenzo Nicora Actor Model

Page 6: Actor model   an approach to concurrency 1.0 (freiburg)

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

Page 7: Actor model   an approach to concurrency 1.0 (freiburg)

7

Supervision

Actors are created by Actors

Parent -> Child

Lorenzo Nicora Actor Model

Page 8: Actor model   an approach to concurrency 1.0 (freiburg)

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

Page 9: Actor model   an approach to concurrency 1.0 (freiburg)

9

Lightweight

Actor is lightweight

Creating an Actor has little overhead beyond creating an Object

Lorenzo Nicora Actor Model

Page 10: Actor model   an approach to concurrency 1.0 (freiburg)

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

Page 11: Actor model   an approach to concurrency 1.0 (freiburg)

11

Example: Non-blocking Request/Response

Lorenzo Nicora Actor Model

Page 12: Actor model   an approach to concurrency 1.0 (freiburg)

12

Example: Non-blocking Request/Response

Lorenzo Nicora Actor Model

Page 13: Actor model   an approach to concurrency 1.0 (freiburg)

13

Example: Non-blocking Request/Response

Lorenzo Nicora Actor Model

Page 14: Actor model   an approach to concurrency 1.0 (freiburg)

14

Example: Non-blocking Request/Response

Lorenzo Nicora Actor Model

Page 15: Actor model   an approach to concurrency 1.0 (freiburg)

15

Example: Non-blocking Request/Response

Lorenzo Nicora Actor Model

Page 16: Actor model   an approach to concurrency 1.0 (freiburg)

16

Example: Non-blocking Request/Response

Lorenzo Nicora Actor Model

Page 17: Actor model   an approach to concurrency 1.0 (freiburg)

17

Example: Non-blocking Request/Response

Lorenzo Nicora Actor Model

Page 18: Actor model   an approach to concurrency 1.0 (freiburg)

18

Example: Non-blocking Request/Response

Lorenzo Nicora Actor Model

Page 19: Actor model   an approach to concurrency 1.0 (freiburg)

19

Example: Non-blocking Request/Response

Lorenzo Nicora Actor Model

Page 20: Actor model   an approach to concurrency 1.0 (freiburg)

20

Example: Non-blocking Request/Response

Lorenzo Nicora Actor Model

Page 21: Actor model   an approach to concurrency 1.0 (freiburg)

21

Example: Non-blocking Request/Response

Lorenzo Nicora Actor Model

Page 22: Actor model   an approach to concurrency 1.0 (freiburg)

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

Page 23: Actor model   an approach to concurrency 1.0 (freiburg)

23Lorenzo Nicora Actor Model