Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 618
hsivonen Avatar asked Sep 19 '08 10:09

hsivonen


People also ask

How many threads Tomcat?

By default, Tomcat sets maxThreads to 200, which represents the maximum number of threads allowed to run at any given time.

What is Servlet container thread?

Web Container is responsible for instantiating the servlet or creating a new thread to handle the request. Its the job of Web Container to get the request and response to the servlet. The container creates multiple threads to process multiple requests to a single servlet. Servlets don't have a main() method.

How many threads can be executed at a spring boot?

Maximum number of threads in Spring Boot Application max-threads to control how many threads you want to allow. This is set to 0 by default which means- use the Tomcat default which is 200 .

How do you check how many threads are running for a process in Linux?

Method 1 – /proc This is the easiest way to see the thread count of any active process on a Linux machine. proc command exports text file of process and system hardware information, such as CPU, interrupts, memory, disk, etc. The above example is having one thread per process.


2 Answers

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.

like image 185
Vilmantas Baranauskas Avatar answered Sep 29 '22 07:09

Vilmantas Baranauskas


No there is not. Keep you number of threads limited and under control so you not exceed system resources, Java's limit is usually around 100-200 live threads.

Good way to do it is by using Executors from java.util.concurrent.

like image 25
Andreas Bakurov Avatar answered Sep 29 '22 08:09

Andreas Bakurov