Ok, this might be a rather silly question, but what is the benefit of using parallel collections within an actor framework? That is, if I’m only dealing with one message at a time from an actor’s mailbox, is there even a need for a parallel collection? Are parallel collections and actors mutually exclusive? What is a use case that would involve both?
Share
They solve different problems . Actors are good at solving task parallel problems. While parallel collections are good at solving data parallel problems. I don’t think they are mutually exclusive – you can use parallel collections in actors and parallel collections containing actors.
Edit – quick test:
Even something simple like a actor notification loop benefits.
In the following code we register a million actors with an actor registry which has to notify them of an event.
The non-parallel notification loop (
registry foreach {}) takes an average of 2.8 seconds on my machine (4 core 2.5 GHz notebook).When the parallel collection loop (
registry.par.foreach {}) is used it takes 1.2 seconds and uses all four cores.