Search code examples
javaakkadistributed-computingdistributedakka-cluster

What do Akka's ActorSystem corresponds to, especially in cluster technology?


sorry if I'll be a little noobish here. I'm studying Java Akka and I'm struggling to grasp the exact meaning of an ActorSystem. I understand it's like an Actor factory, effectively creating the actors I may want to use in my application.

However, I am confused about two things, particularly regarding the Akka cluster usage.

  • The first is minor: in my application, is the ActorSystem unique? I've heard that while it is technically possible to have more than one, usually you only have one system per JVM. Is it true? Would you ever need to use more than one system in your project?

  • The big one: I need to familiarize with the Akka cluster mechanism. When I am distributing my application, what extra conceptual meaning do the ActorSystem get? Does it correspond to the notion of "node"? Or of "cluster"? For what I got, my machine correspond to a single cluster, which in turn comprises multiple nodes. Is it correct? Where do ActorSystems kick in in this reasoning?

    Thanks in advance for your time!


Solution

  • As far as the actors inside the ActorSystem are concerned, actors in a different ActorSystem may as well be in a different JVM (modulo possible classloader conflicts, etc.).

    It's exceptionally rare to need to have multiple ActorSystems in the same JVM: about the only situation where you would strictly need it is a situation like wanting multiple configurations for some functionality in the same JVM (and the functionality being configured isn't flexible about where configuration lives; most/all of Akka's functionality is flexible in this way). Apart from that, multiple ActorSystems in the same JVM is sometimes useful in tests to save the overhead of multiple JVMs.

    So in a cluster, another ActorSystem is definitely listening on a different host:port combination. It's almost certainly running in a different JVM/OS process. It may or may not be running on a different computer.

    An ActorSystem will nearly always correspond 1:1 to a cluster node. It's possible to imagine an implementation that speaks Akka Remoting/Akka Cluster which allows 1 ActorSystem to serve as multiple nodes.