itamar
itamar

Reputation: 1940

Ideal thread pool size in other multi-threaded framework

I'm using a multi threaded framework (Apache Tomcat), and writing my own service (inside a resource) that uses a fixed thread pool size (Java ExecutorService) in order to run its tasks.

How to determine the ideal pool size with respect to the framework or other service's pools?

Upvotes: 0

Views: 1010

Answers (2)

Stephen C
Stephen C

Reputation: 719576

There is no way to determine the "ideal" pool size without running applications in the web container in the production environment (on the production hardware, etc) with a representative workload.

In other words, make the pool size a configuration parameter and tune it.

And if your are running multiple applications in the same web container, you need to tune them together.


The reason I am not giving you a definite recommendation or formula is that the optimal pool size(s) will be highly dependent on the nature of your application and your workload. There are some formulae that supposedly work for idealized tasks, but it is unlikely that they will be better than a "first approximation".

Upvotes: 0

gati sahu
gati sahu

Reputation: 2641

As suggested above there is no fixed rule for thread pool size .But there is some suggestion or best practice available can be used depending upon your use case.

CPU Bound Tasks

For CPU bound tasks, Goetz (2002, 2006) recommends

threads = number of CPUs + 1

IO Bound Tasks

Working out the optimal number for IO bound tasks is less obvious. During an IO bound task, a CPU will be left idle (waiting or blocking). This idle time can be better used in initiating another IO bound request.

Subramaniam (2011, p.31) describes the optimal number of threads in terms of the following formula.

threads = number of cores * (1 + wait time / service time)

Upvotes: 1

Related Questions