Analyzer
Purpose
Section titled “Purpose”The analyzer shows a running actor system as two graphs that are updated periodically. It is suitable for testing, checking and optimizing an actor system (see Fig. 1):
- Structure (left): the hierarchy of the actors. Each ellipse is an actor, the edges lead from parent to child.
- Behaviour (right): the message flow. An edge from actor A to actor B means that A has sent messages to B. The number at the edge is the number of messages sent so far.
Fig. 1: Structure (left) and behaviour (right) of an actor system with two rings, a hub and a tuple (from an earlier version of the example)
In Fig. 1, the message distribution is triggered by a timer. It appears as system, because the timer sends its messages from outside of the user actors.
Relation to Actor4j - Core
Section titled “Relation to Actor4j - Core”ActorAnalyzer is an ActorSystem of Actor4j - Core, based on the default runtime (actor4j-core-runtime). It replaces the message dispatcher with one that copies every message (including directives, alias sends and messages from outside) into the queue of an analyzer thread. The analyzer thread counts the messages per sender and receiver and updates the views in a fixed period. The actors themselves stay unchanged.
The module is split into a UI-independent part and two user interfaces:
| Artifact | Content |
|---|---|
actor4j-analyzer |
ActorAnalyzer, the analyzer thread, the abstract views and the metrics (uses commons-math3) |
actor4j-analyzer-swing |
user interface with Swing and JGraphX |
actor4j-analyzer-fx |
user interface with JavaFX and SmartGraph |
Add the module of the user interface, it includes actor4j-analyzer:
<dependency> <groupId>io.actor4j</groupId> <artifactId>actor4j-analyzer-swing</artifactId> <version>2.5.0</version></dependency>For JavaFX, use actor4j-analyzer-fx instead.
Example: Swing
Section titled “Example: Swing”The analyzer is created like an actor system. The analyzer thread and the user interface are passed to it:
ActorAnalyzerConfig config = ActorAnalyzerConfig.builder() .parallelism(4) .build();
ActorSystem system = ActorAnalyzer.create( new SwingActorAnalyzerThread(2000, true, true, true, new SwingVisualActorAnalyzer()), config);
// add actors as usualActorId ping = system.addActor(() -> new Actor("ping") { @Override public void receive(ActorMessage<?> message) { // ... }});
system.start(); // opens the window and starts the analyzer thread// ...system.shutdownWithActors(true); // stops the analyzer thread and closes the windowThe parameters of SwingActorAnalyzerThread (and FXActorAnalyzerThread) are:
| Parameter | Meaning |
|---|---|
delay |
period of the updates in milliseconds |
showDefaultRoot |
shows an additional root vertex actor4j above the root actors in the structure view |
showRootSystem |
shows the children of the system root actor as well (default false) |
colorize |
colors the actors by the thread they are bound to (default false, see below) |
ActorAnalyzerConfig is an ActorSystemConfig with the name actor4j-analyzer and the sleep mode as thread mode. The Swing window offers different layouts (organic, horizontal, vertical) for both views via the menu Layout.
The complete example (rings, hub and ping-pong, triggered by a timer) is io.actor4j.analyzer.swing.example.ExampleAnalyzer in the module.
Example: JavaFX
Section titled “Example: JavaFX”With JavaFX, the application is a subclass of FXAnalyzerApplication. It provides the user interface via getVisualActorAnalyzer(). The actor system is created in run, after the stage was prepared, and shut down in stop:
public class MyAnalyzer extends FXAnalyzerApplication { protected ActorSystem system;
@Override public void run(Stage primaryStage) { super.run(primaryStage);
system = ActorAnalyzer.create( new FXActorAnalyzerThread(2000, true, true, true, getVisualActorAnalyzer()), ActorAnalyzerConfig.builder().parallelism(4).build()); // add actors as usual system.start(); }
@Override public void stop() { system.shutdownWithActors(true); }
public static void main(String[] args) { launch(args); }}The complete example is io.actor4j.analyzer.fx.example.ExampleAnalyzer. Without the JavaFX module path, start it via io.actor4j.analyzer.fx.example.Launcher, a plain class whose main calls the application.
Colors
Section titled “Colors”| Color | Meaning |
|---|---|
| yellow | root actors of the system (user, system, unknown, pseudo) |
| green | actors (without colorize) |
| one color per thread | actors with colorize: all actors bound to the same thread get the same color |
| light grey | actors with colorize that are not bound to a thread |
| white | the additional root vertex actor4j (showDefaultRoot) |
An actor is labeled with its name. Without a name, its alias is used, otherwise its id.
Colorized Actors Linked to Threads
Section titled “Colorized Actors Linked to Threads”In the default runtime, the actors are bound to threads, and actors that communicate a lot can be grouped on the same thread (ActorGroupMember). With colorize, the analyzer shows this distribution. In the following example, 16 ring groups were distributed equally across 16 threads. The members of a ring group always belong to the same thread. The master node of every ring group extends the class ActorWithBothGroups (implements ActorDistributedGroupMember and ActorGroupMember). All other ring members extend the class ActorWithGroup (implements ActorGroupMember).
Fig. 2: 16 ring groups on 16 threads
In the next example, the 16 ring groups were distributed equally across four threads. This results in four times four ring groups of the same color that belong to the same thread.
Fig. 3: 16 ring groups on four threads
Metrics in the Status Line
Section titled “Metrics in the Status Line”With every update, the status line shows metrics of the behaviour view. The system root actor and its children are left out.
| Metric | Meaning |
|---|---|
| Active Actors | actors that have sent messages |
| Directed Edges | number of sender and receiver pairs |
| Interactional Complexity | directed edges divided by the square of the active actors, in percent |
| Mean, Min, Max, SD, Median, Skewness | statistics of the number of messages per edge |
| Weighted Interactional Complexity | interactional complexity multiplied by median divided by mean |
Own User Interfaces
Section titled “Own User Interfaces”Further user interfaces can be connected via the interface VisualActorAnalyzer (start, stop, structure, behaviour, status) and a subclass of BaseActorAnalyzerThread that implements update(...) and passes the work to the UI thread. The abstract classes VisualActorStructureView and VisualActorBehaviourView contain the logic of both views, only the graph operations (add or remove vertices and edges) have to be implemented.