Scala Italy 2015 - An Introduction to Akka and the Actor-Based Model

Scala Italy 2015 - An Introduction to Akka and the Actor-Based Model

Concurrency has always been a challenging area due to its complexity and unpredictability. Thanks to its Actor-Based Model, Akka provides a tool to tackle concurrency issues and easily create performant and scalable applications. In this talk we will describe what Akka is, what are the advantages of using it and how to use it -- or probably we should say "how not to use it"! We will also discuss Actors and their life cycle. Finally, we will provide examples of their four core operations: create, send, become and supervise actors.

E99b07644586e9e1723757bf8e34ea68?s=128

Daniela Sfregola

May 08, 2015
Tweet

Transcript

  1. 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
  2. Outline Motivation: Concurrency Thread-Lock-Monitor Approach Message-Passing Approach Akka as Message-Passing

    Framework Actors in Akka Actor Life Cycle Actors Hierarchy Supervision Rules Demo An Introduction to Akka and the Actor-Based Model 2/14
  3. Motivation: Concurrency Low Cost Hardware Multiple Core CPUs Distributed Systems

    Big Data Parallelism We need to deal with shared resources between processes! An Introduction to Akka and the Actor-Based Model 3/14
  4. Thread-Lock-Monitor Approach Thread-Lock-Monitor approach can be challenging: Logic complicated for

    humans Difficult to design and maintain High unpredictability Do we have an easier approach to tackle concurrency problems? An Introduction to Akka and the Actor-Based Model 4/14
  5. Message-Passing Approach The Message-Passing Approach: Encapsulates all the shared information

    in messages Messages are used to communicate between processes An Introduction to Akka and the Actor-Based Model 5/14
  6. Akka as Message-Passing Framework Akka - from akka.io Build powerful

    concurrent & distributed applications more easily. Simple Concurrency & Distribution Resilient by Design High Performance Elastic & Decentralized Extensible It supports Scala, Java... .NET is coming soon! An Introduction to Akka and the Actor-Based Model 6/14
  7. Actors in Akka Lightweight concurrent entity Event-driven Mailbox of messages

    processed asynchronously Can hold status/mutability An Introduction to Akka and the Actor-Based Model 7/14
  8. 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
  9. 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
  10. Supervision Rules Your Father is your Supervisor Every Actor has

    a Supervisor, but the Guardian Actor (/user) Your Children follow your destiny If unable to handle an exception, escalate it to your Supervisor If the Guardian Actor is unable to handle an exception, the system will shutdown An Introduction to Akka and the Actor-Based Model 10/14
  11. Actor Core Operations There are four core operations on Actors:

    create send become supervise An Introduction to Akka and the Actor-Based Model 11/14
  12. Demo Demo Time! Gist available at https://gist.github.com/DanielaSfregola/ 6dc52bffa2ed566de9b2 An Introduction

    to Akka and the Actor-Based Model 12/14
  13. Conclusions Akka as Message-Passing approach to concurrency Main components: Actors

    Best Practices: Never Block Communicate only via messages Messages should be immutable Messages should be complete and self-contained An Introduction to Akka and the Actor-Based Model 13/14
  14. Conclusions Akka as Message-Passing approach to concurrency Main components: Actors

    Best Practices: Never Block Communicate only via messages Messages should be immutable Messages should be complete and self-contained Thank you! An Introduction to Akka and the Actor-Based Model 14/14