Supervision and Monitoring in Akka

What is supervision?

Describes a dependency relationship between actors, the parent and child releationship. Parent is unique because it has created the child actor, so the parent is responsible for reacting when failures happens in his child.

And parent decides which choice is need to be selected. When a parent receives the failure signal from it’s child, depends on the nature of failure the parent decides from following options:

Resume: Parent starts the child actor keeping it internal state.

Restart: Parent starts the child actor by clearing it’s internal state.

Stop: Stop the child permanently.

Escalate: Escalate the failure by failing itself and propagate failure to its parent.

akka-life-cycle

Akka Actor Life Cycle

It is always important to view an part of supervision hierarchy, which explains the escalate option. Each supervisor should cover with all possible failure cases.

guardians

Actor System

Source: doc.akka.io

/user: The User Guardian Actor

Actor created using system.actorOf() are children of user guardian actor. Whenever user guardian terminates all user created actors will be terminated too. Top level user created actors are determined by user guardian actor that how they will be supervised. Root Guardian is the supervisor of user guardian.

/root: The Root Guardian

The root guardian actor is the father all actor system. It supervises user guardian actor and system guardian actor.

Supervision Strategies

There are two type of supervision strategies that we follows to supervise any actor:

  1. One-For-One Strategy

  2. One-For-All Strategy

Example of One-For-One Strategy

What is Monitoring?

Lifecycle Monitoring in Akka is usually referred to as DeathWatch

Monitoring is thus used to tie one actor to another so that it may react to the other actor’s termination, in contrast to supervision which reacts to failure.

Monitoring

Monitoring is particularly useful if a supervisor cannot simply restart its children and has to terminate them, e.g. in case of errors during actor initialization. In that case it should monitor those children and re-create them or schedule itself to retry this at a later time.

Code Repository : Supervision and Monitoring  

References: akka.io/docs


KNOLDUS-advt-sticker

Written by 

Prabhat is a Sr. Software Consultant with more than 2 years of experience in C, C++, Java, MySQL, and Scala. His interests are in Cyber Security, Web Development, and New technologies. Prabhat developed software and website on different platforms which include VB6, VB.NET, ASP.NET, PHP, Wordpress, OpenCart, SMF, VBulletin, HTML5, MyBB. Prabhat is focused and result oriented, self-motivated and team-oriented and effective team player.

5 thoughts on “Supervision and Monitoring in Akka

Leave a Reply

%d bloggers like this: