An introduction to Tomcat concurrent optimization method
- 2020-06-23 02:30:13
- OfStack
There are three common operating modes of Tomcat: bio,nio and apr. apr is recommended for production environment. Please refer to the previous blog Tomcat -- Operating Mode for details.
Install APR
[root@liuyazhuang ~]# yum -y install apr apr-devel openssl-devel
[root@liuyazhuang ~]# tar zxvf tomcat-native.tar.gz
[root@liuyazhuang ~]# cd tomcat-native-1.1.24-src/jni/native
[root@liuyazhuang native]# ./configure � with-apr=/usr/bin/apr-1-config � with-ssl=/usr/include/openssl/
[root@liuyazhuang native]# make && make install
The following prompt will appear after installation
Libraries have been installed in:
/usr/local/apr/lib
Setting the environment variable for tomcat is also required after successful installation by adding one line to the catalina.sh file:
Add:
============
# OS specific support. $var _must_ be set to either true or false.
cygwin=false
darwin=false
==============
CATALINA_OPTS= " -Djava.library.path=/usr/local/apr/lib "
Modify the conf/ ES27en.xml corresponding to the 8080 terminal
protocol= " org.apache.coyote.http11.Http11AprProtocol "
After starting tomcat, view the logs
more TOMCAT_HOME/logs/catalina.out
Apr 07, 2017 11:49:12 AM org.apache.catalina.core.AprLifecycleListener init
INFO: Loaded APR based Apache Tomcat Native library 1.1.31 using APR version 1.3.9.
Apr 07, 2017 11:49:12 AM org.apache.catalina.core.AprLifecycleListener init
INFO: APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
Apr 07, 2017 11:49:12 AM org.apache.catalina.core.AprLifecycleListener initializeSSL
INFO: OpenSSL successfully initialized (OpenSSL 1.0.1e 11 Feb 2013)
Apr 07, 2017 11:49:13 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler [ " http-apr-8080 " ]
Apr 07, 2017 11:49:13 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler [ " ajp-apr-8009 " ]
Apr 07, 2017 11:49:13 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 1125 ms
Tomcat optimization
1. JVM tuning
In TOMCAT_HOME/bin/catalina sh increase the following statement, the concrete numerical value as the case may be.
Add to CATALINA_OPTS above:
JAVA_OPTS=-Xms512m -Xmx1024m -XX:PermSize=512M -XX:MaxNewSize=1024m -XX:MaxPermSize=1024m
Parameters,
-Xms JVM initializes heap memory size
-Xmx JVM heap maximum memory
-Xss thread stack size
-ES66en :PermSize JVM Non-heap area initial memory allocation size
-ES70en :MaxPermSize JVM Non-heap maximum memory
Suggestions and Notes:
The -ES79en and -ES80en options are set to the same heap memory allocation to avoid resizing the heap after each GC. Heap memory is recommended to account for 60% to 80% of the memory. Non-heap memory is non-recoverable memory, depending on the project; The thread stack size is recommended at 256k.
32G memory configuration is as follows:
JAVA_OPTS=-Xms20480m -Xmx20480m -Xss1024K -XX:PermSize=512m -XX:MaxPermSize=2048m
2. Close the DNS reverse query
in < Connector port= "8080" add the following parameter
enableLookups= " false "
3. Use APR
For specific installation operations, see the beginning of this article
4. Optimize tomcat parameters
<Connector port= " 8080 "
protocol= " org.apache.coyote.http11.Http11AprProtocol "
connectionTimeout= " 20000 " // Link timeout
redirectPort= " 8443 "
maxThreads= " 500 " // Setting the maximum number of threads to process customer requests determines how many servers can simultaneously respond to customer requests , The default 200
minSpareThreads= " 20 " // Initializes the number of threads, minimum number of free threads, default 10
acceptCount= " 1000 " // When all available threads for processing requests are used, the number of requests that can be placed in the processing queue will not be processed, default 100
enableLookups= " false "
URIEncoding= " UTF-8 " />
conclusion
Above is all about Tomcat concurrent optimization method introduced in this paper, interested friends can continue to see, optimize configuration of Tomcat (memory, concurrent, caching, etc) method, rounding, introduction to Tomcat3 running modes, open Tomcat JMX service method is introduced, such as if there is any deficiency, welcome message said, hope to be of help.