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)
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With