Reputation: 935
How can I process in serial and in parallel these messages based on even numbers? For instance when i
is 2,4,6,8... to process the messages in parallel.
I think that the messages are processed in serial anywise but how can I differentiate to process them in parallel?
for(i <- 1 to 100) {
greeter ! WhoToGreet("message: " + i)
inbox.send(greeter, Greet)
val Greeting(message) = inbox.receive(10.seconds)
println(message)
}
I've changed application.conf
to be as follows:
akka {
actor{
default-dispatcher {
type = Dispatcher
executor = "thread-pool-executor"
throughput = 100
fork-join-executor {
parallelism-min = 2
parallelism-factor = 2.0
parallelism-max = 8
}
}
}
}
but I'm not sure if that's the way or by using par.
I there any way to see when are processed in serial and when in parallel?
Upvotes: 0
Views: 1532
Reputation: 11751
If you need messages processed in parallel you will need more than one actor. As @kaktusito mentioned, one way of doing that is using an Akka router.
You can experiment with number of actors you want to have to processes the messages in parallel. For example, for message#4 you can only have 4 actors at max. But for message#32 you either use 4 or 16 or 32 actors. The number of physical cores of your machine will also determine the number of actors you should run in parallel.
Upvotes: 1
Reputation: 6242
The actors process messages serially. This is part of the model. This ensures that you don't have to think about shared state and locking and so on. In my humble opinion, for what you want to do, you should use some special actor for handling each kind of message and/or make some router actor for it.
http://doc.akka.io/docs/akka/snapshot/scala/routing.html
NOTE: there's nothing to touch in application.conf about it.
Upvotes: 1