Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Concurrency, Actor model and Akka

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
Avatar for Ayushi Ayushi
September 26, 2019

Concurrency, Actor model and Akka

The talk intends to convey the common problems of building concurrent systems and how a concept called Actor Model alleviates some of these problems and helps us build saner concurrent systems. We also see some real-world applications and use a popular actor framework - Akka - to realize the concept of Actor Model in code in concurrent as well as a distributed setup. We will look deeper into Akka actors, their pros and cons and finally some best practices.
Whole talk at: https://www.youtube.com/watch?v=X4U8hlr6jzA

Avatar for Ayushi

Ayushi

September 26, 2019
Tweet

More Decks by Ayushi

Other Decks in Programming

Transcript

  1. AYUSHI SHARMA Software Engineer, Avalara R&D Worked on: u Data

    pipeline tool (MDA) u Classification Ops u Search u HS Code Classification
  2. INDEX u Why even talk about it – what are

    the issues? u What is the Actor Model ? u Components of Actor Model u How does it solve the addressed issues? u Akka Actor model u Akka Actor model primitives
  3. WHY TALK ABOUT IT? u Encapsulation u Concurrency u Parallelism

    u Resource management u Failure/ error handling (ext. Fault Tolerance) BANK ACCT 1 ACCT 2 ACCT 3 ACCT 4 W T D W T W T D D
  4. u Actor is the fundamental unit of computation which has:

    • Address • State • Behaviour • Create more actors • Send messages. • Designate what to do with the next message (update it’s local state for next message) • Mailbox Isolated mutable state + Asynchronous messaging
  5. 2. MESSAGE PASSING u Communication between actors through messages u

    Asynchronous u Immutable messages u Best efforts delivery u At-most once u Order not preserved (among actors)
  6. 3. EXECUTION ENVIRONMENT u Engine that runs all actors. u

    Like execution contexts in respective languages.
  7. BANK ACTOR BANK MAILBOX ACCT1 ACCT MAILBOX ACCT2 ACCT MAILBOX

    ACCT3 ACCT MAILBOX D W W D W D T T D2 W1 W2 D1 D3 W3
  8. u Encapsulation via message passing. u Eliminates race condition u

    Resource management u Simple to reason u Fault tolerance (let it crash, self heal & responsive) u Exploit potential of modern CPUs u Distribution
  9. Threading model Actor model Models****** Behaviour and state Communication Communication

    Method invocation Message passing State Shared Isolated Concurrency Threads Actors Synchronization Locks, mutexes, semaphores - Control flow Mostly Synchronous Completely asynchronous
  10. ACTOR SYSTEM & LIFECYCLE u Collaborating ensemble of actors arranged

    in a hierarchy. u Initial actors(guardians): • Root • System • User u User actors = sub-tasks u Resource cleanup u Death watch
  11. CONS OF ACTOR MODEL u Serialization/Deserialization cost involved in message

    passing. u Overflowing mailbox u Mandates applications manage message guarantee and ordering u Not trivial to test u Code cleanliness
  12. ACTOR BEST PRACTICES 1. Event driven and non-blocking 2. Passing

    immutable messages 3. Do not send behavior within messages 4. Create user actors sparingly