Should an actor run CPU-Intensive work on the IO-Dispatcher Thread?

We read from a CassandraReadJournal, map the data, convert it to JSON, and then write it to some output.

The JSON is quite big, maybe 50-100 KB.

  • Should we run the JSON Stage on the “akka.stream.default-blocking-io-dispatcher”?

  • I only read about running blocking io on that thread, but what about cpu-intense work?

It’s right that you might have to separate cpu intensive work to a different dispatcher, but that should typically not be the same as the dispatcher for blocking IO because the task are typically very different in nature.

For blocking IO it is fine to have more threads than cores, since those threads will be mostly waiting.

For cpu intensive work it’s most efficient to limit the number of threads to the number of cores. Perhaps slightly less than number of cores to give the system some room for doing other things.

There are also other ways than the dispatcher to limit number of things running in parallel, such as a limited number of actors or streams with limited parallelism. In that case it’s fine to run those things on the default-dispatcher.

1 Like