Scala Execution Context and Dispatchers - Listing and comparison: Why ?
There are a lot of questions around what/how/what is the best Execution Context
to use to execute futures on in Scala and how to configure the dispatcher.
Still I never was able to find a longer list with pros and cons and configuration examples.
The best I could find was in the Akka Documentation: http://doc.akka.io/docs/akka/snapshot/scala/dispatchers.html and Play Documentation https://www.playframework.com/documentation/2.5.x/ThreadPools.
I would like to ask what configurations besides the scala.concurrent.ExecutionContext.Implicits.global
and Akka defaults you use in your daily Dev lives, when you use them and what are the pros and cons .
Here are some of the ones I already have:
First unfinished overview
Standard: scala.concurrent.ExecutionContext.Implicits.global
use when unsure
Easy to use
- shared for everything
may use up all your CPU
more Info: http://www.scala-lang.org/api/2.11.5/index.html#scala.concurrent.ExecutionContext
Testing - ExecutionContext.fromExecutor(new ForkJoinPool(1))
- use for testing
- no parallelism
Play's default EC - play.api.libs.concurrent.Execution.Implicits._
- use instead of
scala.concurrent.ExecutionContext.Implicits.global
when using Play - Play default
shared
more Info: https://www.playframework.com/documentation/2.5.x/ThreadPools
Akka`s default Execution Context
based on configuration
more Info: http://doc.akka.io/docs/akka/snapshot/scala/dispatchers.html
Bulkheading
ExecutionContext.fromExecutor(new ForkJoinPool(n)) based on an separated dispatcher . Thanks to Sergiy Prydatchenko
ExecutionContext.fromExecutor(new ForkJoinPool(n))
(or a separate Akka dispatcher) may be used not only for testing but for bulkheading (separating part of yourFutures
from another in terms ofExecutor
). – Loom