2019.9.22 Tomcat's three operating modes (BIO, NIO, AIO also called apr)

1 , synchronized concepts:

  • Synchronization : own personally held bank card to the bank to withdraw money (use synchronous IO time, the Java deal with their own IO read and write).
  • Asynchronous : commission a younger brother to take the bank card to the bank to withdraw money, and then give you (using asynchronous IO time, the Java the IO read and write entrusted to the OS processing, data needs to be passed to the buffer address and size of the OS ( bank cards and passwords ) , OS needs to support asynchronous IO operations API ).
  • Obstruction : ATM queue withdrawals, you have to wait (to use blocking IO when, the Java invocation blocks until the reader to complete before returning).
  • Non-blocking : counter withdrawals, take a number, and then sitting in a chair doing anything else, you will be notified of the equal sign broadcast deal with, not to the number you just can not go, you can always ask the manager lined up in the lobby did not, lobby manager also said that if no you can not go to (the use of non-blocking IO when, if you can not read and write Java call will return immediately, when IO event dispatcher will inform the reader can continue to read and write, read and write continuously loop until completion).

2 , the Java for BIO , NIO , AIO support:

  • BIO the Java : synchronization and blocking, server mode to achieve a thread connection, that the client has a connection request on the server side need to start a thread for processing, if the connection does not do anything to cause unnecessary overhead of thread, of course you can improved by the thread pool mechanism.
  • The NIO java : non-blocking synchronization, the server requests a mode of realization of a thread, i.e. the connection request sent by the client are registered to the multiplexer, the multiplexer is connected to the polling I / O when a request to start a thread for processing.
  • AIO the Java ( NIO.2 ): non-blocking asynchronous server mode to achieve a valid request a thread, client I / O requests are from OS to complete the application and then notify the server to start a thread for processing

3 , BIO , NIO , AIO applicable scene analysis :

  • BIO

BIO method is applicable to a relatively small number of connections and fixed architecture, server resources in this way is relatively high, limited concurrent applications, the JDK1.4 previously the only option, but the procedure is simple and easy to understand intuitively , the performance is very poor, without any optimization and support .

  • NIO

Nio (new I / O), is a new I / O operation and later versions of the java SE1.4 (i.e. java.nio package and its sub-packet). Java nio is based on a buffer, and can provide non-blocking I / O operations java API, nio therefore also be regarded as non-blocking I / O abbreviation. It has a better performance than conventional concurrently running I / O operations (bio). Applies to the number of connections is large and a relatively short connection (light operation) architecture, such as chat server, limited concurrent applications.

  • APR

The most difficult to install, but from the operating system level to solve the problem of asynchronous IO, greatly improving performance

 

 

 

Tomcat8 default operating mode for the NIO

[root@localhost ~]# tail -1 /usr/local/tomcat8/logs/catalina.out

08-Apr-2019 11:45:01.589 信息 [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]

 

[root@localhost ~]# vim /usr/local/tomcat8/conf/server.xml

    <Connector port="8080" protocol="org.apache.coyote.http11.Http11NioProtocol"

               connectionTimeout="20000"

               redirectPort="8443"

               compression="on"

               compressionMinSize="50"

               noCompressionUserAgents="gozilla, traviata"

compressableMimeType="text/html,text/xml,text/javascript,text/css,text/plain" />

[root@localhost ~]# /usr/local/tomcat8/bin/shutdown.sh

[root@localhost ~]# /usr/local/tomcat8/bin/startup.sh

[root@localhost ~]# tail -f /usr/local/tomcat8/logs/catalina.out

08-Apr-2019 11:56:02.441 信息 [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]

 

Model three Apr : 

[root@localhost ~]# rpm -e apr --nodeps

[root@localhost ~]# yum -y install apr  apr-devel

[root@localhost ~]# cp /usr/local/tomcat8/bin/tomcat-native.tar.gz /root/

[root@localhost ~]# tar xf tomcat-native.tar.gz

[root@localhost ~]# cd tomcat-native-1.2.12-src/native/

[root@localhost native]# ./configure --with-apr=/usr/bin/apr-1-config --with-java-home=/usr/local/java && make && make install

----------------------------------------------------------------------

Libraries have been installed in:

   /usr/local/apr/lib

 

If you ever happen to want to link against installed libraries

in a given directory, LIBDIR, you must either use libtool, and

specify the full pathname of the library, or use the `-LLIBDIR'

flag during linking and do at least one of the following:

   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable

     during execution

   - add LIBDIR to the `LD_RUN_PATH' environment variable

     during linking

   - use the `-Wl,-rpath -Wl,LIBDIR' linker flag

   - have your system administrator add LIBDIR to `/etc/ld.so.conf'

 

See any operating system documentation about shared libraries for

more information, such as the ld(1) and ld.so(8) manual pages.

----------------------------------------------------------------------

 

[root@localhost tomcat-native-1.2.17-src]# cd

[root @ localhost Native] # vim /usr/local/tomcat8/bin/catalina.sh ## added at the end, set the environment variable

CATALINA_OPTS="-Djava.library.path=/usr/local/apr/lib"

[root@localhost native]# vim /usr/local/tomcat8/conf/server.xml     

69 <Connector Port = "8080" Protocol = "org.apache.coyote.http11.Http11AprProtocol" [the root @ localhost ~] # VI m  / etc / Profile ## to the last line

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/apr/lib

[root @ localhost Native] # Source / etc / profile      // loading process file profile

[root@localhost native]# /usr/local/tomcat8/bin/shutdown.sh

[root@localhost native]# /usr/local/tomcat8/bin/startup.sh

[root@localhost ~]# netstat -utpln |grep java

tcp        0      0 0.0.0.0:8080            0.0.0.0:*               LISTEN      2748/java           

tcp        0      0 127.0.0.1:8005          0.0.0.0:*               LISTEN      2748/java

[root@localhost native]# tail -3 /usr/local/tomcat8/logs/catalina.out

08-Apr-2019 12:20:20.455 信息 [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8009"]

 

Solve restart tomcat after service, 8005 port problems delayed start;

[root@localhost ~]# vi /usr/local/java/jre/lib/security/java.security       

117 securerandom.source = file: / dev / urandom // tomcat modified random number, to facilitate loading port delay 8005

Guess you like

Origin www.cnblogs.com/otherwise/p/11569170.html