How to choose the max thread count for an HTTP servlet container?

concurrency, http, java, optimization, servlets

Solution

Very simple and primitive one:

max_number_of_threads = number_of_CPUs * C

Where C depends on other factors of your application :-)

Ask yourself following questions:

- Will your application be CPU intensive (lower C) or spend most time waiting for a third systems (higher C)?

- Do you need quicker response times (lower C) or be able to serve many multiple users at once even if each request takes longer (higher C).

Usually I set C rather low, e.g. 2 - 10.

Problem

I'm developing a restful Web service that runs as a servlet (using blocking IO) in Jetty. Figuring out the optimal setting for max threads seems hard. Is there a researched formula for deciding the max number of threads from some easily measurable characteristics of the rest of the setup?

Original source