2

After reading most of the Akka docs, I still don't understand something fairly fundamental to Akka: actor cardinality.

Meaning, if I have a particular actor, say FizzActor, does Akka ever only create 1 instance of it, or does it spawn n-instances of it as needed? If it can spawn multiple instances of an actor class, then is this configurable (if so how/where?), or does Akka alone determine how many instances to create? Does stopping/restarting/resuming this actor class perform the action on all instances of the actor or just the one child instance? Can I assume that Akka coordinates state changes across all FizzActor instances, so that each time I get an ActorRef to it, I see a consistent state?

None of these seem to be covered in the docs!

smeeb
  • 27,777
  • 57
  • 250
  • 447

1 Answers1

2

Akka's primary philosophy is "no magic", i.e. if you create an actor that's what happens - one Actor is created. Refer to the docs on Creating Actors with Props for a deeper explanation.

The one case where Akka takes care of starting multiple Actors in your stead is Pool Routers, which as explained in the docs:

Pool - The router creates routees as child actors and removes them from the router if they terminate

Konrad 'ktoso' Malawski
  • 13,102
  • 3
  • 47
  • 52
  • Thanks @Konrad (+1) - then is it even *possible* to create multiple instances of the same actor class, if so, how/where in the config/code? Also, if so, what about my other questions (does stopping the actor stop all instances or just the one? will Akka coordinate state change across all instances or not)? Thanks again so much! – smeeb Jun 22 '15 at 09:23
  • 1
    Actors are like people – autonomous :-) `context.stop(self)` stops the one Actor, yourself - any stopping of other Actors requires telling them to stop (`juliet ! PoisonPill`) or the parent actor stopping its children, please read the docs on Supervision: http://doc.akka.io/docs/akka/snapshot/general/supervision.html – Konrad 'ktoso' Malawski Jun 22 '15 at 10:18