UP | HOME
../../

DIC Distributed Actor System

Table of Contents

This is part of Akka Actors with Scala.

1 Distributed Actor System

  1. Let use a tentative def of Distributed Actor System. A collection of Akka actors actually running on multiple machines that are networked.
  2. In this section, our goal is to understand this typical diagram.

fig-actor-path.png

Figure 1: Distributed Actor System

1.1 Actor References

  1. Actor references may be obtained by (i) creating actors or (ii) looking them up
  2. Typically, we create actors beneath the guardian actor using the ActorSystem.actorOf method and then …
  3. Spawn the actor tree using ActorContext.actorOf.

1.1.1 Looking up Actors by Concrete Path

  1. ActorSystem.actorSelection method
  2. Send a message, such as the built-in Identify message, to the actor and use the sender reference of a reply from the actor.
  3. actorFor is deprecated in favor of actorSelection because actor references acquired with actorFor behave differently for local and remote actors. Beware: actorOf vs. actorSelection vs. actorFor
  4. Matching on paths similar to shells «*» and «?»: context.actorSelection("../*") ! msg

1.1.2 Absolute vs. Relative Paths

  1. Send a message to a specific sibling:
  2. context . actorSelection ("../brother") ! msg
  3. Absolute paths: context.actorSelection("/user/serviceA") ! msg

1.2 Remote Actors and Akka Clusters

  1. Remote Actors ActorSystem configuration

fig-actor-remote-1.png

Figure 2: Remote Actors ActorSystem configuration

1.3 Clusters

  1. Automatic cluster-wide deployment
  2. Decentralized P2P gossip-based cluster membership
  3. Leader “election”
  4. Adaptive load-balancing (based on runtime metrics)
  5. Automatic replication with automatic fail-over upon node crash
  6. Automatic adaptive cluster rebalancing
  7. Highly available configuration service

1.4 Enable Clustering

akka {
  actor {
    provider = "akka.cluster.ClusterActorRefProvider"
    ...
  }

  extensions = ["akka.cluster.Cluster"]

  cluster {
    seed-nodes = [
      "akka://ClusterSystem@127.0.0.1:2551",
      "akka://ClusterSystem@127.0.0.1:2552"
    ]
    auto-down = on
  }
}

1.5 Remote Deployment

2 Termination

What Does "Finished" Mean? The most natural answer to this question appears to be, "When all the Mailboxes are empty." Natural, yes; correct, no. :)

fig-terminated-q.png

Figure 4: Actor System terminated?

2.1 The Reaper

fig-the-reaper.png

Figure 5: Actor System Reaper

2.2 Reaper Source Code

import akka.actor.{Actor, ActorRef, Terminated}
import scala.collection.mutable.ArrayBuffer

object Reaper { case class WatchMe(ref: ActorRef); }

abstract class Reaper extends Actor {
  import Reaper._
  val watched = ArrayBuffer.empty[ActorRef]

  /* Derivations must implement this method. Called 
   * when everything is dead */

  def allSoulsReaped(): Unit

  final def receive = {
    case WatchMe(ref) =>
      context.watch(ref)
      watched += ref
    case Terminated(ref) =>
      watched -= ref
      if (watched.isEmpty) allSoulsReaped()
  }
}

2.3 PoisonPill

fig-akka-poison-pill.png

Figure 6: Application with PoisonPill

3 References

  1. https://doc.akka.io/docs/akka/current/ Nearly all the code snippets and figures are from here. Reference.
  2. Jonas Boner, "Above the Clouds: Introducing Akka", 2011. Web search. Video or pdf. Highly recommended.

4 End


Copyright © 2020 www.wright.edu/~pmateti • 2020-01-31