@petabridge Petabridge.com
Concurrency Without the Pain:

An Intro to the Actor Model
Andrew	
  Skotzko	
  
Co-­‐founder	
  —	
  Petabridge
@petabridge Petabridge.com
@petabridge Petabridge.com
Why	
  should	
  we	
  care	
  about	
  
concurrency?
@petabridge Petabridge.com
1970	
  -­‐	
  2005
@petabridge Petabridge.com
@petabridge Petabridge.com
@petabridge Petabridge.com
@petabridge Petabridge.com
@petabridge Petabridge.com
TANSTAAFL
“There	
  ain’t	
  no	
  such	
  thing	
  as	
  a	
  free	
  lunch.”	
  
—R.	
  A.	
  Heinlein,	
  The	
  Moon	
  Is	
  a	
  Harsh	
  Mistress
@petabridge Petabridge.com
@petabridge Petabridge.com
WTF	
  are	
  you	
  talking	
  about?
@petabridge Petabridge.com
Concurrency.
Time	
  to	
  make	
  friends.
@petabridge Petabridge.com
So	
  what’s	
  the	
  problem?
@petabridge Petabridge.com
How to Write Multithreaded Code
Shared State
Programming
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
protected shared
memory (what?!?!)
Finish work on one
thread
Consume that work on
another
@petabridge Petabridge.com
Shared State Programming Sucks
(Illustrated)
Shared State
Programming
Problems
Synchronizing shared state == pit
of doom
Deadlocks
Livelocks
Unsafe state
Coordinating work between threads
Debugging multi-threaded code:
not for the faint of heart
Hey, that third party code you're
using - is it thread safe?
Writing thread-safe code is hard
@petabridge Petabridge.com
Random?
• .NET 4.0: TPL (2010)
• .NET 4.5: async/await (2012)
@petabridge Petabridge.com
Is there a better way? THERE MUST BE!
THERE.	
  
MUST.	
  
BE.	
  
A.	
  
BETTER.	
  
WAY!
@petabridge Petabridge.com
Warning!
Mind Blowingly Different
Programming Style Ahead!
@petabridge Petabridge.com
Warning! Mind Blowingly Different
Programming Style Ahead!
@petabridge Petabridge.com
The Actor Model
@petabridge Petabridge.com
What	
  is	
  the	
  actor	
  model?
@petabridge Petabridge.com
Everything	
  is	
  an	
  actor.
@petabridge Petabridge.com
@petabridge Petabridge.com
@petabridge Petabridge.com
3 Core Abilities
1. Send	
  messages	
  
2. Create	
  other	
  actors	
  
3. Change	
  behavior
@petabridge Petabridge.com
Messages
@petabridge Petabridge.com
Actors work by passing each other
messages
@petabridge Petabridge.com
Message passing in action
Send "Hello" to "/user/actor1"
Received "Hello" from
"/user/actor2"
(do some work)
Send "Sup homedawg" to "/user/actor2"
@petabridge Petabridge.com
BUZZWORD	
  
BINGO!
@petabridge Petabridge.com
Example Akka.NET Message
@petabridge Petabridge.com
Actors send messages to addresses
akka.tcp://MySystem@localhost:9001/user/actorName1
Protocol
ActorSystem
Address
Path
All parts form an "ActorPath"
@petabridge Petabridge.com
Actor addresses have location
transparency
@petabridge Petabridge.com
Which means…
@petabridge Petabridge.com
@petabridge Petabridge.com
@petabridge Petabridge.com
Magical scaling sauce!
(more on that later)
@petabridge Petabridge.com
ReactiveManifesto.org
@petabridge Petabridge.com
What is Akka.NET?
@petabridge Petabridge.com
Obligatory logos to impress you
@petabridge Petabridge.com
This is an actor
@petabridge Petabridge.com
These are messages
@petabridge Petabridge.com
Actors run on threads
@petabridge Petabridge.com
Actors are lazy
@petabridge Petabridge.com
Process messages one at a time
@petabridge Petabridge.com
The circle of life
@petabridge Petabridge.com
Actor lifecycle
@petabridge Petabridge.com
Actor lifecycle
@petabridge Petabridge.com
@petabridge Petabridge.com
Hierarchies
@petabridge Petabridge.com
Supervision
@petabridge Petabridge.com
Switchable Behavior
@petabridge Petabridge.com
Magic Scaling Sauce!!!
@petabridge Petabridge.com
(High Availability)
@petabridge Petabridge.com
We Can Deploy Actors and Send
Messages Anywhere
Nice hair!
Did you hear?
My hair
rocks!
Dude, don't
encourage
him.
@petabridge Petabridge.com
Scaling Out
• Actors can be deployed anywhere
• Special "Router" actors distribute work
• Actors can be easily restarted and
redeployed
@petabridge Petabridge.com
And Can Form Highly Available Systems
Ready for
work!
@petabridge Petabridge.com
http://LearnAkka.net
@petabridge Petabridge.com
Have questions? Ask us!
andrew@petabridge.com	
  
Intro:	
  http://learnakka.net	
  
@petabridge Petabridge.com
Hierarchies pt. deux
@petabridge Petabridge.com
Error Kernel

Akka.NET: Concurrency Without the Pain (Intro to the Actor Model)