Reputation: 21557
Couldn't find any info on this. I have a Akka/Spray based service and was always using ExecutionContext.global
if i wanted to write some async code with std scala Future. Are there any benefits from using a dispatcher in akka based app rather than importing a global one? And also are there are any disadvantages from mixing (some parts are using akka's dispatcher and other parts scale's global)?
Upvotes: 5
Views: 1202
Reputation: 988
Don't use Akka default Dispatcher for execution of blocking calls in Future-s - in this case you can get all your Actors sitting on the default Dispatcher fully hanged in case of all threads of the default Dispatcher are blocked by blocking calls in such Future-s.
Usage of different Dispatcher-s for different Actor types (and especially for Future-s that do blocking calls) is known as Bulkhead Pattern.
ExecutionContext.global is a ForkJoinPool (by default) that use scala.concurrent.context.minThreads/maxThreads/numThreads settings for configure number of threads. So, IMHO, you can use it for Future-s execution instead of any other Akka Dispatcher with fork-join-executor.
But I would suggest to use a separate Akka Dispatcher for bulkheading just to have all Dispatchers configured in a single place (in Akka config).
Upvotes: 6