Akka is a event driven, asynchronous, distributed framework which help in doing asyc event handling. Akka is reactive which gives him power to handle faults, become responsive, elastic.
2. What is akka?
Event Driven
Asynchronous
Distributed
Reactive
Responsive: Respond in timely manner if possible
Resilient: Responsive in case of failure
4. Actors
Light weight object (around 300 bytes of memory)
Accept messages and do whatever they are supposed to do with them
Process one message at a time
Each actor has messaging queue
Asynchronous
Serializable and passed to other clients/actors
5. Why actors, why not threads
Concurrency : When two threads are making progress. Parallelism that can
include time slicing.
Parallelism: When two threads are executing simultaneously.
Shared states are real evil. Can cause race condition, dead locks, blocking
calls.
Actors keep mutable state internal.
Actors communicate through messages. No shared state between outside
7. Akka Components
ActorSystem: Actor, ActorRef, MessageDispatcher, Mailbox, Message Queue.
ActorRef: Addressable destination of actor
MessageDispatcher:
Engine that runs parts of actor system and schedule all activity. Main responsibility to run
mailbox.
ActorRef -> MessageDispatcher -> MessageQueue of destination mailbox
Mailbox: Hold actors. Takes message from message queue and invokes a
actor.
8. Actor Hierarchies and path
All actors belong to actor hierarchies in actor system.
Two separate hierarchies:
System Hierarchies : Manage internal tasks
User hierarchies : Defines actor for our application
User level root actor (named Guardian) under which all actors are created.
Actor Path: akka://MySystem@MyServer:MyPort/user/TopActor/ChildActor
akka is the name of the scheme
9. Supervise
Actor can supervise other actors
Supervisor detects and respond to failures
On actor crash, a notification is send to its supervisor to decide what to do
Helps provide clean separation between error handling and message
processing
Fault handling strategy:
10. Supervision and Monitoring
Every actor has a supervisor who created the current one.
Responsible for watching its subordinates and handling their problem.
Actor detects failure and suspend itself. Supervisor helps by :
Resume its subordinate
Restart the subordinate
Terminate permanently
Escalate the failure to its supervisor
11. Routers
Type of actor
Layer between ActorRef and Actor
Route Message to underlying actor
Non cluster example:
Round robin
Consistent hashing
Random etc
12. Use case
Processing pipeline
Streaming data
Multi-user concurrency (as one actor run at one time)
Systems high uptime requirement (Supervisor make sure actor is live)
Application with shared state