Q: How-to create 1 million actors in parallel? This is just an learning example.
I have an actor which holds an list of 1 million ids
(This is just an stripped down example. In real life these actors could represent bank accounts and I would send them "tell" or "broadcast" messages. So I want to keep them all at the same time in memory)
I want this actor to create 1 million child actors (one for each id)
Is there a more parallel way than this code?
receive (Msg,..) {

 ids.stream().forEach(
           id -> {
                    context().actorOf(MyActor.props(id));
                }
    );
}


A: And why not to use a BroadcastRouter for the children?
val children = system.actorOf(Props[ChildrenActor].withRouter(
      BroadcastRouter(nrOfInstances = amountOfChildren)))

This is in case you only need to send messages to all the children every single time. In the case you need to send both broadcast and individual messages to the children, you can use a ConsistentHashingRouter instead to map the messages with the children ids.

A: You can convert a collection to a parallel one to make traversing it concurrent:
scala> (0 to 20).par.foreach(print)
10211345071289151618192061171314

