Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tomcat NIO thread pools

I understand Java NIO (channels, selector, ..). I would like to understand Tomcat NIO better so that I can configure thread pools of Tomcat appropriately from Spring boot.

Can someone please explain what is the purpose of each thread pool and how do these work in relevance to Java NIO? It would be helpful if you can also point out which thread pool is used during the processing of HTTP requests.

Some Tomcat8 thread pools observed during thread dumps:

http-nio-<port>-Acceptor (usually 1 or 2 threads)
http-nio-<port>-ClientPoller-<index> (usually 2)
http-nio-<port>-exec-<index> (usually 10)
NioBlockingSelector.BlockPoller-<index> (usually 2)
like image 765
Rag Avatar asked Nov 21 '16 14:11

Rag


People also ask

Does Tomcat use thread pool?

Tomcat manages the workload for processing requests with worker threads and tracks thread usage for each connector under either the ThreadPool MBean type, or the Executor Mbean type if you are using an executor. The Executor MBean type represents the thread pool created for use across multiple connectors.

What happens when Tomcat runs out of threads?

If the server doesn't have enough threads, the server will wait until a thread becomes available before processing a request. In extreme cases, those requests that get queued may never get processed, if the wait time exceeds a server timeout value.

How does Tomcat NIO connector work?

The NIO connector (non-blocking I/O) is a bit more complicated. It uses the java NIO library and multiplexes between requests. It has two thread pools – one holds the the poller threads, which handle all incoming requests and push these requests to be handled by worker threads, held in another pool.

Is Tomcat single threaded?

By default, Tomcat allocates a single thread to perform deployment and management of applications. When multiple applications are handled by a single Tomcat instance, this can cause the startup time to increase considerably, as each application is started in sequence by the management thread.


1 Answers

http-nio--exec- (usually 10) => This can be controlled by setting "server.tomcat.max-threads=10" in application.properties. If its set to 1, then you see only one thread http-nio--exec-1.

I am too trying to find out other thread pools.

like image 84
Subra M Avatar answered Sep 18 '22 16:09

Subra M