Tomcat - NIO

Web/WAS 2018.09.29 09:28


In HTTP 1.1, all connections between the browser and the server are considered persistent unless declared otherwise. Persistence, in this context, means to use a single TCP connection to send and receive multiple HTTP requests/responses, as opposed to opening a new connection for every single request/response pair.

In tomcat, the default HTTP connector is blocking and follows a one thread per connection model. This means that in order to serve 100 concurrent users, it requires 100 active threads. We end up wasting resources (the thread) because connections may not be used heavily, but just enough to avoid a timeout.

Opposed to this is the relatively new NIO or non blocking connector. This connector has a couple of poller threads used to keep the connection alive for all connected users while worker threads are called whenever data (a new HTTP request) is available. This model leads to a much better sharing of resources (threads) and a larger number of concurrent users can be served from the same server.

In order to configure tomcat to use the Non-blocking NIO connector instead of the default blocking BIO one simply change the value of the protocol attribute of the connector tag in the server.xml from HTTP/1.1 to org.apache.coyote.http11.Http11NioProtocol

<Connector connectionTimeout="20000" maxThreads="1000" port="8080" protocol="org.apache.coyote.http11.Http11NioProtocol" redirectPort="8443"/>

To verify that you indeed are using the NIO connector, take a look at the startup logs. You should see lines similar to this.

Mar 28, 2014 3:59:04 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-nio-8080"]
Mar 28, 2014 3:59:04 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector

Use VisualVM to look at the threads being created in both cases. You’ll find NIO to use threads much more efficiently.


source - https://dzone.com/articles/understanding-tomcat-nio






default(HTTP/1.1) on the Tomcat 7.0.91

9월 29, 2018 9:42:26 오전 org.apache.coyote.AbstractProtocol init

INFO: Initializing ProtocolHandler ["http-bio-8080"]

9월 29, 2018 9:42:26 오전 org.apache.coyote.AbstractProtocol init

INFO: Initializing ProtocolHandler ["http-bio-8443"]

9월 29, 2018 9:42:27 오전 org.apache.coyote.AbstractProtocol init

INFO: Initializing ProtocolHandler ["ajp-bio-8009"]


default(org.apache.coyote.http11.Http11NioProtocol) on the Tomcat 9.0.8

9월 29, 2018 9:56:08 오전 org.apache.coyote.AbstractProtocol init

INFO: Initializing ProtocolHandler ["http-nio-8080"]

9월 29, 2018 9:56:08 오전 org.apache.tomcat.util.net.NioSelectorPool getSharedSelector

INFO: Using a shared selector for servlet write/read

9월 29, 2018 9:56:08 오전 org.apache.coyote.AbstractProtocol init

INFO: Initializing ProtocolHandler ["https-jsse-nio-8443"]

9월 29, 2018 9:56:08 오전 org.apache.tomcat.util.net.NioSelectorPool getSharedSelector

INFO: Using a shared selector for servlet write/read

9월 29, 2018 9:56:08 오전 org.apache.coyote.AbstractProtocol init

INFO: Initializing ProtocolHandler ["ajp-nio-8009"]



references 

https://tomcat.apache.org/tomcat-8.0-doc/ssl-howto.html

https://en.wikipedia.org/wiki/Java_Secure_Socket_Extension


'Web > WAS' 카테고리의 다른 글

Tomcat - NIO  (0) 2018.09.29
was - certbot tomcat  (0) 2017.02.21
tomcat - At least one JAR was scanned for TLDs yet contained no TLDs  (0) 2016.10.12
tomcat - jmx, jstatd  (0) 2016.04.28
tomcat - Resource Links  (0) 2015.12.17
tomcat - Using resources  (0) 2015.12.12
Posted by linuxism