I have an actor pool of 100 Acting Actors that share the theft manager with its CorePoolSize set to 100. But now, sending 19 messages to one of the Actors, 19 messages are not parallelized with 19 Actors, there are only 5 messages working in parallel. When these 5 messages are completed, the next 5 messages are processed by the same 5 Actors again and so on. Why are my 19 messages not working in parallel, what am I missing here?
My code looks basically like this:
object TestActor { val dispatcher = Dispatchers.newExecutorBasedEventDrivenWorkStealingDispatcher("pool") .setCorePoolSize(100) .setMaxPoolSize(100) .build } class TestActor(val name: Integer) extends Actor { self.lifeCycle = Permanent self.dispatcher = TestActor.dispatcher def receive = { case num: Integer => { println("Actor: " + name + " Received: " + num) Thread.sleep(10000) } } } trait CyclicLoadBalancing extends LoadBalancer { this: Actor => val testActors: List[ActorRef] val seq = new CyclicIterator[ActorRef](testActors) } trait TestActorManager extends Actor { self.lifeCycle = Permanent self.faultHandler = OneForOneStrategy(List(classOf[Exception]), 5, 5000) val testActors: List[ActorRef] override def preStart = testActors foreach { self.startLink(_) } override def postStop = self.shutdownLinkedActors() } val supervisor = actorOf(new TestActorManager with CyclicLoadBalancing { val testActors = (1 until 100 toList) map (i => actorOf(new TestActor(i))) }).start println("Number of Actors: " + Actor.registry.actorsFor(classOf[TestActor]).length) val testActor = Actor.registry.actorsFor(classOf[TestActor]).head (1 until 20 toList) foreach { testActor ! _ }
Exit:
Actor: 4 Received: 16 Actor: 3 Received: 17 Actor: 1 Received: 19 Actor: 59 Received: 1 Actor: 2 Received: 18 // 10 secs. are passing.. Actor: 4 Received: 15 Actor: 3 Received: 14 Actor: 1 Received: 13 Actor: 59 Received: 2 Actor: 2 Received: 12 // 10 secs. are passing.. Actor: 4 Received: 11 Actor: 3 Received: 10 Actor: 59 Received: 3 Actor: 2 Received: 8 Actor: 1 Received: 9 // 10 secs. are passing.. Actor: 4 Received: 7 Actor: 3 Received: 6 Actor: 59 Received: 4 Actor: 2 Received: 5
edit: I am using Akka 1.0
scala akka
rocksteady
source share