Akka – a toolkit for concurrent systems



Akka – a toolkit for concurrent systems

0 0


Akka.Talk


On Github scala-meetup-mvd / Akka.Talk

Akka

a toolkit for concurrent systems

Federico Silva

@fedesilva / slides at github

Akka

Federico Silva

  • One significant Akka App
  • Several smaller things in the middle
  • Now starting to build on Akka again

What is Akka?

Akka.io

Akka is a toolkit and runtime for building highly concurrent, distributed, and resilient message-driven applications on the JVM.

What is Akka?

  • A toolkit
  • A runtime
  • JVM based
  • Written in Scala

What is Akka?

  • Concurrent
  • Parallel

What is Akka?

Concurrent

What is the innovation?

What makes it different and why is it important?

Why is concurrency important?

  • Modern CPUs
  • Many CPUs
  • Many Computers

Why do we need something new?

  • Need more control
  • Need clear semantics
  • Less coupling
  • Fault tolerance
  • Distribution?
  • Threads are not enough
  • Neither are thread pools
  • or Fork/Join

What is Akka?

What does it bring to the table?

A unified model for concurrency and distribution via the Actor Model

Actor Model

Old concept

"A Universal Modular Actor Formalism for Artificial Intelligence".

Carl Hewitt; Peter Bishop; Richard Steiger (1973).

Actor Model

The actor model in computer science is a mathematical model of concurrent computation that treats "actors" as the universal primitives of concurrent computation: in response to a message that it receives, an actor can make local decisions, create more actors, send more messages, and determine how to respond to the next message received.

Actor Model

Other implementations

  • Ruby, Celluloid
  • Erlang, language construct, OTP adds features
  • .NET, dotsero, Akka.net, MS Orleans

Actor Model

  • Message Passing
  • Location transparency
  • Isolation
  • Supervision
  • Monitoring
  • Dynamic behaviour

Message Passing

Is the basic building block, other features build upon it

  • Asynchronous delivery
  • Isolation
  • Location transparency

Isolation

Ability to control internal state, run without interference

Location Transparency

Ability to send a message without considering where the recipient is located

Supervision and Monitoring

Actor systems form hierarchies where each node is the supervisor of its children.

Supervision and Monitoring

  • Supervisors can delegate long running tasks
  • Worker nodes need not consider fault management
  • Cooperatively solve problems, under watch from supervisor
  • Supervisor gets messages when children die, can restart, kill others

Dynamic Behaviour

An actor can change its own behaviour in response to messages.

Can be though of as a state machine.

Actors in Akka

  • Actor Reference
  • State
  • Behavior
  • Mailbox
  • Children
  • Supervisor Strategy
  • When an Actor Terminates

Look at some code

Simple Akka Seed from Activator ©

App from template Implement Switch Actor Look at CounterActor

Other Akka modules

  • Cluster
  • Persistence
  • FSM
  • Camel
  • HTTP
  • Reactive Streams

Akka Cluster

  • Remoting
  • Routing
  • Load Balancing

Akka Persistence

  • Evented architectures, CQRS
  • Commands, backed by WAL
  • Persistence of state, with recovery

Reactive Streams

Better alternative, safer too

What is not SO good?

What is not SO good?

Dynamic Behaviour! No help from the type system Closing over state is not tracked Invisible Mailbox Actors? Futures? Both? When? Too low level

Patterns or good practices

  • Minimize work, delegate lengthy work
  • Pull don't push
  • Ask for flow control
  • Use functions to create behaviour, pass state
  • Use traits to isolate code
  • Use different dispatchers for different sections of the app

Anatomy of an application

Simple Seed Distributed Workers

Misc

Data locality Modeling data as an actor? CQRS like

References

Akka

Actor model

Typesafe Activator

Hewitt's original paper