AKKA

What is AKKA

We believe that writing correct concurrent, fault-tolerant and scalable applications is too hard. Most of the time it's because we are using the wrong tools and the wrong level of abstraction. Akka is here to change that. Using the Actor Model we raise the abstraction level and provide a better platform to build scalable, resilient and responsive applications—see the Reactive Manifesto for more details. For fault-tolerance we adopt the "let it crash" model which the telecom industry has used with great success to build applications that self-heal and systems that never stop. Actors also provide the abstraction for transparent distribution and the basis for truly scalable and fault-tolerant applications

Actors

Actors give you:

  • Simple and high-level abstractions for concurrency and parallelism.
  • Asynchronous, non-blocking and highly performant event-driven programming model.
  • Very lightweight event-driven processes (several million actors per GB of heap memory).

Fault Tolerance

  • Supervisor hierarchies with "let-it-crash" semantics.
  • Supervisor hierarchies can span over multiple JVMs to provide truly fault-tolerant systems.
  • Excellent for writing highly fault-tolerant systems that self-heal and never stop.

Persistence

Messages received by an actor can optionally be persisted and replayed when the actor is started or restarted. This allows actors to recover their state, even after JVM crashes or when being migrated to another node.

Actor Systems

Actors are objects which encapsulate state and behavior, they communicate exclusively by exchanging messages which are placed into the recipient’s mailbox. In a sense, actors are the most stringent form of object-oriented programming, but it serves better to view them as persons: while modeling a solution with actors, envision a group of people and assign sub-tasks to them, arrange their functions into an organizational structure and think about how to escalate failure (all with the benefit of not actually dealing with people, which means that we need not concern ourselves with their emotional state or moral issues). The result can then serve as a mental scaffolding for building the software implementation.

Note

An ActorSystem is a heavyweight structure that will allocate 1…N Threads, so create one per logical application.

 

Actor Systems

Hierarchical Structure

Supervision and Monitoring

  1. Resume the subordinate, keeping its accumulated internal state
  2. Restart the subordinate, clearing out its accumulated internal state
  3. Stop the subordinate permanently
  4. Escalate the failure, thereby failing itself

Actor References, Paths and Addresses

An actor reference is a subtype of ActorRef,

whose foremost purpose is to support sending

messages to the actor it represents.

 

Each actor has access to its canonical (local) reference through the self field; this reference is also included as sender reference by default for all messages sent to other actors.

"akka://my-sys/user/service-a/worker1"

// purely local

"akka.tcp://my-sys@host.example.com:5678/user/service-b"

// remote

DEMO

  • OOXX on torrentkitty
  • Java (ajax)
  • Spring-AKKA(scala snapshot)
  • Q&A