As for `availableProcessors()/3 + 1` formula, it’s...
# ktor
o
As for
availableProcessors()/3 + 1
formula, it’s because we use 3 thread pools for connections, framework code, and user code. Connection pool accepts socket connection, creates an inbound data channel and that is. Depending on the host it does slightly different things, but generally it is that simple. Framework pool is doing things that we can control to be non-blocking, like parsing HTTP requests, creating an
ApplicationCall
, processing cookies, headers, etc. User code pool is where we have no idea what will happen, like if it will or will not block for 30 seconds, so in order to keep things running we offload it to the 3rd pool. Hence,
Cores/3 + 1
is fine to keep CPU busy but not pay too much for thread switching. Making it less or more would may be improve things in some special cases, like a lot of waiting threads, but as I described above, it’s not the solution to scaling problems in a blocking world.
👍 1