Akka Monitoring and Telemetry
Akka Monitoring and Telemetry
Despite the benefits distributed systems offer, tracing can become problematic. If you use Akka, here is how to get started with monitoring.
Join the DZone community and get the full member experience.Join For Free
How do you break a Monolith into Microservices at Scale? This ebook shows strategies and techniques for building scalable and resilient microservices.
The behavior of actors running in an actor system can be very dynamic. In some cases, the behavior is more organic than mechanical. Some actor systems are relatively simple and lightweight. On the other end of the spectrum, other actor systems are composed of hundreds to thousands to millions of individual running actors.
The lifestyle of different actors varies as well. Some actors live for a long time while others come and go in milliseconds. While some actors are relatively inactive other actors may be extremely chatty, sending and receiving messages as quickly as possible. Things get even more fun and interesting when actor systems are spread across a cluster of networked nodes.
When you implement an actor system, you may think that you know how your carefully crafted actors are going to behave. In most cases this is true, the majority of your actors do what they are expected to do. However, there are times when your actors may do things that you did not expect or anticipate.
Many things can cause actors to do the unexpected or to misbehave. It is one thing to design and implement a system for the happy state when everything is running fine. When there is plenty of CPU and memory capacity, no excessively long stop the world garbage collections, no network problems or the even more problematic network slowdowns, no failed cluster nodes, no unexpectedly large spikes in activity, everything may work well. But, as we well know, it is a tough world out there. Things do go wrong, bad things do happen, and that is when your finely crafted actor system may run into trouble.
It could be that you thought that you actors should behave in one way but something unexpected happens. Maybe there are more instances of some actors than you expected. Perhaps some actors are sending a lot more messages than you expected. One common problem is that some actors cannot keep up with the flow of incoming messages and a potentially lethal backlog of messages accumulates in mailboxes.
So how do you know what is going on in your actor system? One way is to use logging. You can embed various strategically placed log messages that provide some visibility into the happenings inside your actor system. Another way is to use monitoring. If you are a Lightbend subscriber, you have the option to use the Monitoring and Telemetry options that are included with your subscription. Telemetry is also free to use by anyone during the development phase.
Currently, the majority of the Telemetry capabilities are focused on capturing events and metrics from Akka systems. Monitoring for Scala and Lagom is also available, and new telemetry options are planned for future versions. Given the focus here is on Akka we will concentrate on Akka telemetry.
Figure 1: Lightbend Telemetry
The above diagram in Figure 1 was copied from the Lightbend Telemetry documentation. As shown in this diagram, metrics, and events are captured through instrumentation by a Java agent, which is also known as Cinnamon. To get a more detailed overview of how this works, please see the Introduction section of the Telemetry documentation.
The instrumentation provided covers a wide range of events and metrics. Here is a breakdown of the types of information that is available:
- Actor metrics
- Actor remote metrics
- Actor events
- Cluster events
- Cluster metrics
- Split Brain Resolver events
- Threshold events
- Dispatcher events
Please see the Akka Instrumentation documentation for the details.
Some events and metrics are often more interesting than others. For example, the actor metrics for the number of running actors and the mailbox size are often watched more closely than some of the other metrics.
The threshold events are a set metrics that are configured to trigger when specified threshold amounts are exceeded. For example, an actor class or group can be configured to trigger a threshold event when the mailbox size exceeds a specified level. These threshold events could then be set up to trigger alerts in some external support system.
Figure 2: Distributed Tracing
In addition to the events and metrics distributed tracing is provided. As described in the documentation, a trace shows a dataflow or an execution path through a distributed system. Each span in the trace represents a logical unit of work. In the case of actors, each span represents the processing of a message by an actor. Tracing adds another view of actor behavior on top of the events and metrics.
The level of visibility provided by Akka Telemetry can be beneficial at all stages of the software development lifecycle. If you are a Lightbend subscriber, you have the option to use Lightbend Telemetry from the development stage and into production. Also, Lightbend Telemetry is free to use during development.
Getting started is easy. Just follow the directions provided in the documentation.
Published at DZone with permission of Hugh McKee , DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.