haufe #msaday - the actor model: an alternative approach to concurrency by lorenzo nicora
TRANSCRIPT
![Page 1: Haufe #msaday - The Actor model: an alternative approach to concurrency By Lorenzo Nicora](https://reader033.vdocuments.us/reader033/viewer/2022051318/587176971a28ab230b8b5189/html5/thumbnails/1.jpg)
The Actor Model
1
An alternative approach to concurrency
Lorenzo Nicora Senior Consultant @ OpenCredo
@nicusX https://opencredo.com/author/lorenzo/
![Page 2: Haufe #msaday - The Actor model: an alternative approach to concurrency By Lorenzo Nicora](https://reader033.vdocuments.us/reader033/viewer/2022051318/587176971a28ab230b8b5189/html5/thumbnails/2.jpg)
✓ (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: Haufe #msaday - The Actor model: an alternative approach to concurrency By Lorenzo Nicora](https://reader033.vdocuments.us/reader033/viewer/2022051318/587176971a28ab230b8b5189/html5/thumbnails/3.jpg)
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: Haufe #msaday - The Actor model: an alternative approach to concurrency By Lorenzo Nicora](https://reader033.vdocuments.us/reader033/viewer/2022051318/587176971a28ab230b8b5189/html5/thumbnails/4.jpg)
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: Haufe #msaday - The Actor model: an alternative approach to concurrency By Lorenzo Nicora](https://reader033.vdocuments.us/reader033/viewer/2022051318/587176971a28ab230b8b5189/html5/thumbnails/5.jpg)
Actors interacts only by messaging
Actors react to messages
5
Actors are Reactive
Lorenzo Nicora Actor Model
![Page 6: Haufe #msaday - The Actor model: an alternative approach to concurrency By Lorenzo Nicora](https://reader033.vdocuments.us/reader033/viewer/2022051318/587176971a28ab230b8b5189/html5/thumbnails/6.jpg)
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: Haufe #msaday - The Actor model: an alternative approach to concurrency By Lorenzo Nicora](https://reader033.vdocuments.us/reader033/viewer/2022051318/587176971a28ab230b8b5189/html5/thumbnails/7.jpg)
7
Supervision
Actors are created by Actors
Parent -> Child
Lorenzo Nicora Actor Model
![Page 8: Haufe #msaday - The Actor model: an alternative approach to concurrency By Lorenzo Nicora](https://reader033.vdocuments.us/reader033/viewer/2022051318/587176971a28ab230b8b5189/html5/thumbnails/8.jpg)
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: Haufe #msaday - The Actor model: an alternative approach to concurrency By Lorenzo Nicora](https://reader033.vdocuments.us/reader033/viewer/2022051318/587176971a28ab230b8b5189/html5/thumbnails/9.jpg)
9
Lightweight
Actor is lightweight
Creating an Actor has little overhead beyond creating an Object
Lorenzo Nicora Actor Model
![Page 10: Haufe #msaday - The Actor model: an alternative approach to concurrency By Lorenzo Nicora](https://reader033.vdocuments.us/reader033/viewer/2022051318/587176971a28ab230b8b5189/html5/thumbnails/10.jpg)
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: Haufe #msaday - The Actor model: an alternative approach to concurrency By Lorenzo Nicora](https://reader033.vdocuments.us/reader033/viewer/2022051318/587176971a28ab230b8b5189/html5/thumbnails/11.jpg)
11
Example: Non-blocking Request/Response
Lorenzo Nicora Actor Model
![Page 12: Haufe #msaday - The Actor model: an alternative approach to concurrency By Lorenzo Nicora](https://reader033.vdocuments.us/reader033/viewer/2022051318/587176971a28ab230b8b5189/html5/thumbnails/12.jpg)
12
Example: Non-blocking Request/Response
Lorenzo Nicora Actor Model
![Page 13: Haufe #msaday - The Actor model: an alternative approach to concurrency By Lorenzo Nicora](https://reader033.vdocuments.us/reader033/viewer/2022051318/587176971a28ab230b8b5189/html5/thumbnails/13.jpg)
13
Example: Non-blocking Request/Response
Lorenzo Nicora Actor Model
![Page 14: Haufe #msaday - The Actor model: an alternative approach to concurrency By Lorenzo Nicora](https://reader033.vdocuments.us/reader033/viewer/2022051318/587176971a28ab230b8b5189/html5/thumbnails/14.jpg)
14
Example: Non-blocking Request/Response
Lorenzo Nicora Actor Model
![Page 15: Haufe #msaday - The Actor model: an alternative approach to concurrency By Lorenzo Nicora](https://reader033.vdocuments.us/reader033/viewer/2022051318/587176971a28ab230b8b5189/html5/thumbnails/15.jpg)
15
Example: Non-blocking Request/Response
Lorenzo Nicora Actor Model
![Page 16: Haufe #msaday - The Actor model: an alternative approach to concurrency By Lorenzo Nicora](https://reader033.vdocuments.us/reader033/viewer/2022051318/587176971a28ab230b8b5189/html5/thumbnails/16.jpg)
16
Example: Non-blocking Request/Response
Lorenzo Nicora Actor Model
![Page 17: Haufe #msaday - The Actor model: an alternative approach to concurrency By Lorenzo Nicora](https://reader033.vdocuments.us/reader033/viewer/2022051318/587176971a28ab230b8b5189/html5/thumbnails/17.jpg)
17
Example: Non-blocking Request/Response
Lorenzo Nicora Actor Model
![Page 18: Haufe #msaday - The Actor model: an alternative approach to concurrency By Lorenzo Nicora](https://reader033.vdocuments.us/reader033/viewer/2022051318/587176971a28ab230b8b5189/html5/thumbnails/18.jpg)
18
Example: Non-blocking Request/Response
Lorenzo Nicora Actor Model
![Page 19: Haufe #msaday - The Actor model: an alternative approach to concurrency By Lorenzo Nicora](https://reader033.vdocuments.us/reader033/viewer/2022051318/587176971a28ab230b8b5189/html5/thumbnails/19.jpg)
19
Example: Non-blocking Request/Response
Lorenzo Nicora Actor Model
![Page 20: Haufe #msaday - The Actor model: an alternative approach to concurrency By Lorenzo Nicora](https://reader033.vdocuments.us/reader033/viewer/2022051318/587176971a28ab230b8b5189/html5/thumbnails/20.jpg)
20
Example: Non-blocking Request/Response
Lorenzo Nicora Actor Model
![Page 21: Haufe #msaday - The Actor model: an alternative approach to concurrency By Lorenzo Nicora](https://reader033.vdocuments.us/reader033/viewer/2022051318/587176971a28ab230b8b5189/html5/thumbnails/21.jpg)
21
Example: Non-blocking Request/Response
Lorenzo Nicora Actor Model
![Page 22: Haufe #msaday - The Actor model: an alternative approach to concurrency By Lorenzo Nicora](https://reader033.vdocuments.us/reader033/viewer/2022051318/587176971a28ab230b8b5189/html5/thumbnails/22.jpg)
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: Haufe #msaday - The Actor model: an alternative approach to concurrency By Lorenzo Nicora](https://reader033.vdocuments.us/reader033/viewer/2022051318/587176971a28ab230b8b5189/html5/thumbnails/23.jpg)
23Lorenzo Nicora Actor Model