With NIO connector set in Tomcat we have N pooler threads and M worker threads.
With BIO connector set we can have N*M threads in thread pool. So what will be the difference between two connectors ?
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.
NIO mode enables Tomcat to simultaneously handle multiple connections per thread by using poller threads to keep connections alive and worker threads to process incoming requests.
Connector elements are Tomcat's links to the outside world, allowing Catalina to receive requests, pass them to the correct web application, and send back the results through the Connector as dynamically generated content.
However, Tomcat also supports Non-Blocking I/O. It is said that it supports near 13,000 simultaneous requests in NIO mode. Still, there is a limit. The acceptCount attribute defines the maximum number of HTTP connections that will be put in a queue while there is no free connection available to serve.
In BIO each new connection is allocated a thread from the Connector thread pool and that thread stays assigned to that connection until the connection closes. This means threads are idle for long periods of time between requests (i.e. during HTTP keep-alive).
In NIO, each new connection is passed to the Poller. A Poller thread is notified when there is data on the connection to be processed. The Poller then allocates a thread to the connection from the Connector thread pool and that thread stays assigned to that connection until all the data has been read/written. The connection is then passed back to the Poller so the Poller can monitor for more data.
In short, this makes NIO more scaleable. BIO requires one thread in the thread pool for each connection. NIO can maintain many more connections than BIO and only requires one thread in the thread pool for each concurrently processed request.
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