Date post: | 16-Apr-2017 |
Category: |
Software |
Upload: | arthur-shvetsov |
View: | 50 times |
Download: | 1 times |
Introduction to actor model with examples on Akka.NET
Arthur Shvetsov 1
Overview and history What is an actor model? Akka.NET main concepts Use-case scenarios
Agenda
2
1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 20160
500
1000
1500
2000
2500
3000
3500
4000
0
10
20
30
40
50
60
70
200 200 300 400 500
1000
1800
2530
3200
3600
2200
2930 30003200
3330 33303150 3200 3150 3150 3150 3150
1 1 1 1 1 1 1 1 1 1 2 2 4 48 8
16 16
32 32
64 64
CPU clock speed vs number of cores
CPU clock speed (MHz) # of Cores3
Make classes and functions Find areas where you can do multiple things at once Queue work onto a new thread or thread pool Use synchronization mechanisms to protect shared memory Finish work on one thread Consume that work on another
How we write multithreaded code?
4
5
Statefulness Concurrency Recovering from failures Bottlenecks Availability
Distributed programming pains
6
Multithreading
7
8
- If we don’t want to write multithread code?- Use concurrency abstractions instead
9
We won’t talk about TPL today
10
The Actor Model
11
1973 - Concept formulated by Carl Hewitt et al.: “A universal modular ACTOR formalism for artificial intelligence”
1986 - Gul Agha, doctoral dissertation "Actors: A Model of Concurrent Computation in Distributed Systems“
1986 - Joe Armstrong and others in Ericsson - Erlang programming language and VM.
2009 - initial release of Akka framework (JVM, Scala) 2014.02 - initial release of Akka.NET - Aaron Stannard, Roger
Actor model history
12
The Actor Model provides a higher level of abstraction for writing concurrent and distributed systems.
Actor Model alleviates the developer from having to deal with explicit locking and thread management, making it easier to write correct concurrent and parallel systems.
Actor Model defines some general rules for how the system’s components should behave and interact with each other.
What is an actor model?
13
No deadlocks No shared state No global mutable state Fault isolation – “let it crash” Encapsulation
Actor model benefits
14
Akka.NET is a toolkit and runtime for building highly concurrent, distributed, and fault tolerant event-driven applications on .NET & Mono.
Akka.NET is a port of the popular Java/Scala framework Akka to .NET.
What is Akka.NET?
15
Everything is an actor!
From OOP to Actor Model paradigm shift
16
Actor is a code unit organization
What is actor?
OOP Actor
BehaviorState
Synchronous calls
BehaviorState
Asynchronous messages
17
What is actor?
18
All communication is done via message-passing All messages are immutable Sender and recipient are decoupled, asynchronous
Actors are fundamental units of work & concurrency
19
Process messages Contain private state, invisible from the outside and changes it upon
reception of a message Change behavior between messages (i.e. state machine)
Actors can
20
One message processed at a time Messages processed in FIFO order “At Most Once” delivery guarantied:
at-most-once delivery at-least-once delivery exactly-once delivery
Actors promise
21
Example
22
Switchable Behaviors
23
Actor exists as hierarchies• Parent actors supervise child actors• Actors are resilient to failures
24
One-For-One Strategy vs. All-For-One Strategy
Actor supervision
25
Communicate with actors through “actor reference”
All actors are identified by a unique address
26
Actor addresses have location transparency
27
28
Location transparency Remote addressing Remote messaging Remote deployment
Akka.Remote
29
Thread Instance of an object/component Publisher/Subscriber Singleton or service (e.g. data access layer) State machine Load balancer or router
Actor use cases
30
http://getakka.net/ https://github.com/petabridge/akka-bootcamp
References
31
Thank you!
Arthur Shvetsov
32