Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Getting an Overview of Actors in an Akka System

DZone's Guide to

Getting an Overview of Actors in an Akka System

· Java Zone
Free Resource

Learn how to troubleshoot and diagnose some of the most common performance issues in Java today. Brought to you in partnership with AppDynamics.

I've been playing around with akka-http and akka-streams lately and was wondering which kinds of actors were created when I create flow graphs and process http requests. I ran into the typesafe console, but that is already end of live (https://groups.google.com/forum/#!forum/typesafe-console) and doesn't support the newer versions of akka.

So after some looking around I ran into a post on stackoverflow providing an alternative approach (http://stackoverflow.com/questions/25860939/how-print-all-actors-in-akka...):

listactors.png

This posts lists some pseudo code, which pointed me in pretty much the right direction. I currently use the following actor to print out all the actors in the system:

class IDActor extends Actor with ActorLogging {
 
 def receive = {
    case "start" =>
      log.info("Current Actors in system:")
      self ! ActorPath.fromString("akka://Streams/user/")
 
    case path: ActorPath =>
      context.actorSelection(path / "*") ! Identify(())
 
    case ActorIdentity(_, Some(ref)) =>
      log.info(ref.toString())
      self ! ref.path
  }
}

To start this all we have to do is get the actor and message "start":

val idActor = system.actorOf(Props[IDActor],"idActor"); idActor ! "start"

The result is very interesting. For instance in a http-akka system with a couple of flows running I get the following overview of actors:

Current Actors in system:
Actor[akka://Streams/user/$a/flow-1-2-1-foreach-stageFactory#-1147809628]
Actor[akka://Streams/user/$a/flow-1-2-1-foreach-stageFactory#-1147809628]
Actor[akka://Streams/user/$a/flow-1-2-1-foreach-stageFactory#-1147809628]
Actor[akka://Streams/user/$a/flow-1-2-1-foreach-stageFactory#-1147809628]
Actor[akka://Streams/user/$a/flow-1-2-1-foreach-stageFactory#-1147809628]
Actor[akka://Streams/user/$a#-992619289]
Actor[akka://Streams/user/idActor#830993582]
Actor[akka://Streams/user/$a/flow-1-1-map#310662784]
...
Actor[akka://Streams/user/$a/flow-751-1-prefixAndTail#801612770]
Actor[akka://Streams/user/$a/flow-752-1-prefixAndTail#-1939947471]
Actor[akka://Streams/user/$a/flow-753-1-prefixAndTail#102076528]
Actor[akka://Streams/user/$a/flow-754-1-prefixAndTail#-1858318406]
Actor[akka://Streams/user/$a/flow-755-1-prefixAndTail#595550267]
Actor[akka://Streams/user/$a/flow-756-1-prefixAndTail#-1675014490]
Actor[akka://Streams/user/$a/flow-76-1-map#-1734873421]
Actor[akka://Streams/user/$a/flow-93-1-map#174954170]
Actor[akka://Streams/user/$a/flow-726-1-mapAsync#2041440238]
Actor[akka://Streams/user/$a/flow-725-1-mapAsync#-674218071]
Actor[akka://Streams/user/$a/flow-745-1-mapAsync#-800760294]

Cool right. Not that you can do much with it, but it at least gives you a good overview of what is happening internally.

Understand the needs and benefits around implementing the right monitoring solution for a growing containerized market. Brought to you in partnership with AppDynamics.

Topics:

Published at DZone with permission of Jos Dirksen, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}