2
votes

I'm trying to make a Scala application server based on the classic worker pool model. Given that:

  1. the machine has a quad-core processor
  2. there is a scheduler actor which is dedicated to blocking network I/O to listen
  3. worker actors are all non-blocking.

What would be the best value for corePoolSize to maximize the performance? Ideally the performance is maximized when the size of the worker thread pool is equal to the number of processor cores. So in this case, I guess the best value would be 5 (1 for the scheduler and the other 4 for the workers), or alternatively I could set the value to 4 and override the scheduler method of the scheduler actor so that it will not share the thread pool with the workers.

Is this correct? Any advice appreciated. Thanks!

1

1 Answers

6
votes

Just some hints.

Ideally the performance is maximized when the size of the worker thread pool is equal to the number of processor cores.

Not really. Here is how you could estimate the number of threads at which you can get maximum throughput:

N = C * U * (1 + W/C) 

where N = number of threads, C = number of CPU cores, U = target CPU utilization rate, W/C = Waiting time to Computing time ratio (waiting time means IO etc.).

Note however that the above equation only considers CPU, and CPU isn't the only resource to manage. Tuning for response time would also be a bit different matter.

The cliche answer is that you have to test in order to see what't the best option. You can probably use the above formula as a starting point. Note also that core pool size != max pool size.