daniela sfregola - intro to akka
TRANSCRIPT
An Introduction toAkka and the Actor-Based Model
Daniela Sfregola
@DanielaSfregolahttp://danielasfregola.com/
Scala Italy 2015
An Introduction to Akka and the Actor-Based Model 1/14
Outline
ConcurrencyThread-Lock-Monitor ApproachMessage-Passing ApproachAkka as Message-Passing FrameworkActors in AkkaActor Life CycleActors HierarchySupervision RulesDemo
An Introduction to Akka and the Actor-Based Model 2/14
Motivation: Concurrency
Multiple Core CPUsDistributed SystemsLow Cost HardwareParallelism
We need to deal with shared resource between processes!
An Introduction to Akka and the Actor-Based Model 3/14
Thread-Lock-Monitor Approach
Thread-Lock-Monitor approach can be challenging:
Logic complicated for humansDifficult to design and maintainHigh unpredictability
Do we have an easier approach to tackle concurrency problems?
An Introduction to Akka and the Actor-Based Model 4/14
Message-Passing Approach
The Message-Passing Approach:Encapsulates all the shared information in messagesMessages are used to communicate between processes
An Introduction to Akka and the Actor-Based Model 5/14
Akka as Message-Passing Framework
Akka - from akka.io
Build powerful concurrent & distributed applications more easily.
Simple Concurrency & DistributionResilient by DesignHigh PerformanceElastic & DecentralizedExtensible
It supports Scala, Java... .NET is coming soon!
An Introduction to Akka and the Actor-Based Model 6/14
Actors in Akka
Lightweight concurrent entityEvent-drivenMailbox of messages processed asynchronouslyCan hold status/mutability
An Introduction to Akka and the Actor-Based Model 7/14
Actor Life Cycle
Akka in action (2013) by R. Roestenburg, R. Bakker and R. Williams.Shelter Island: Manning Publication
An Introduction to Akka and the Actor-Based Model 8/14
Actors Hierarchy
from http://doc.akka.io/docs/akka/snapshot/general/supervision.html#supervision,accessed on May 2015
An Introduction to Akka and the Actor-Based Model 9/14
Supervision Rules
Your Father is your SupervisorEvery Actor has a Supervisor, but the Guardian Actor (/user)Your Children follow your destinyIf unable to handle an exception, escalate it to your SupervisorIf the Guardian Actor is unable to handle an exception, the systemwill shutdown
An Introduction to Akka and the Actor-Based Model 10/14
Actor Core Operations
There are four core operations on Actors:
createsendbecomesupervise
An Introduction to Akka and the Actor-Based Model 11/14
Demo
Demo Time!
Gist available athttps://gist.github.com/DanielaSfregola/6dc52bffa2ed566de9b2
An Introduction to Akka and the Actor-Based Model 12/14
Conclusions
Akka as Message-Passing approach to concurrencyMain components: ActorsBest Practices:
Never BlockCommunicate only via messagesMessages should be immutableMessages should be complete and self-contained
An Introduction to Akka and the Actor-Based Model 13/14
Conclusions
Akka as Message-Passing approach to concurrencyMain components: ActorsBest Practices:
Never BlockCommunicate only via messagesMessages should be immutableMessages should be complete and self-contained
Thank you!
An Introduction to Akka and the Actor-Based Model 14/14