daniela sfregola - intro to akka

14
An Introduction to Akka and the Actor-Based Model Daniela Sfregola @DanielaSfregola http://danielasfregola.com/ Scala Italy 2015 An Introduction to Akka and the Actor-Based Model 1/14

Upload: scala-italy

Post on 15-Aug-2015

37 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Daniela Sfregola - Intro to Akka

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

Page 2: Daniela Sfregola - Intro to Akka

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

Page 3: Daniela Sfregola - Intro to Akka

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

Page 4: Daniela Sfregola - Intro to Akka

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

Page 5: Daniela Sfregola - Intro to Akka

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

Page 6: Daniela Sfregola - Intro to Akka

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

Page 7: Daniela Sfregola - Intro to Akka

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

Page 8: Daniela Sfregola - Intro to Akka

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

Page 9: Daniela Sfregola - Intro to Akka

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

Page 10: Daniela Sfregola - Intro to Akka

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

Page 11: Daniela Sfregola - Intro to Akka

Actor Core Operations

There are four core operations on Actors:

createsendbecomesupervise

An Introduction to Akka and the Actor-Based Model 11/14

Page 12: Daniela Sfregola - Intro to Akka

Demo

Demo Time!

Gist available athttps://gist.github.com/DanielaSfregola/6dc52bffa2ed566de9b2

An Introduction to Akka and the Actor-Based Model 12/14

Page 13: Daniela Sfregola - Intro to Akka

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

Page 14: Daniela Sfregola - Intro to Akka

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