"Best" ExecutionContext for IO
Asked Answered
P

0

8

I have some synchronous calls in my Scala code. I've wrapped them in a blocking() context and then in a Future: Future(blocking(syncCall())), but I don't know which type of ExecutionContext to use.

I know there may be a lot of possibilities and that there is not an ExecutionContext that it's the "best". I just need some information in order not to choose the worst because there is a lot of information out there and I have a mess in my head.

Pontonier answered 24/6, 2016 at 13:35 Comment(6)
Why are you wrapping the call in a blocking context if you're running this inside a Future. Why not Future(syncCall())?Boson
@YuvalItzchakov to notify the ExecutionContext that it's a blocking call, read github.com/alexandru/scala-best-practices/blob/master/sections/…Pontonier
Good read, thanks. Following that section (4.6) says: Related to Rule 4.4, if you're doing a lot of blocking I/O (e.g. a lot of calls to JDBC), it's better to create a second thread-pool / execution context and execute all blocking calls on that, leaving the application's thread-pool to deal with CPU-bound stuff.. Why not use that advice?Boson
@YuvalItzchakov that is my intention and this is why I'm asking for some help on that, because I don't know which thread pool to use. Also, 4.6 does not invalidate rule 4.4Pontonier
Scala's ExecutionContext doesn't do any thread scheduling on its own, but rather passes the job to the underlying java.util.concurrent.ExecutorService. So your question boils down to the following: which type of ExecutorService should one use for IO tasks.Craigcraighead
I would suggest go with section 4.11 in the reading above. Introduce few system properties where you can define your thread-pool: maxPool size, initialPool size etc.Jamie

© 2022 - 2024 — McMap. All rights reserved.