Question

I have a bunch of Actors (Akka 2) that need to communicate with a background system synchronously.

Is there something wrong with just having the Actors use a separate dedicated dispatcher and perform the processing synchronously like

def receive = {
  case Foo(foo) => sender ! getFooSynchronously(foo)
  case Bar(bar) => sender ! getBarSynchronously(bar)
}

or should I use futures like the following?

def receive = {
  case Foo(foo) => Future { getFooSynchronously(foo) } pipeTo sender
  case Bar(bar) => Future { getBarSynchronously(bar) } pipeTo sender
}

If I am not mistaken, using Futures would allow to ask the Actor for Foo and Bar in parallel and join the results, which is not possible with the synchronous approach. Taking into account that I don't need the parallel processing: is it more efficient to use a dedicated dispatcher and avoid the creation of the futures?

Was it helpful?

Solution

A dedicated dispatcher is in order either way, if you ultimately need more concurrent getSynchronously() operations than default dispatcher max pool size.

But to your question I agree with @rob-starling , both are fine & have their uses.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top