3 ways to optimize Tomcat performance in high concurrency environment
As the most commonly used Java web server, Tomcat's performance will drop sharply as the amount of concurrency increases. Is there any way to optimize the performance of Tomcat in a high-concurrency environment?
written in front
Tomcat running mode
protocol = "org.apache.coyote.http11.Http11NioProtocol"
protocol = "org.apache.coyote.http11.Http11AprProtocol"
Tomcat concurrency optimization
Install APR
[root@binghe ~]# yum -y install apr apr-devel openssl-devel [root@binghe ~]# tar zxvf tomcat-native.tar.gz [root@binghe ~]# cd tomcat-native-1.1.24-src/jni/native [root@binghe native]# ./configure --with-apr=/usr/bin/apr-1-config --with-ssl=/usr/include/openssl/ [root@binghe native]# make && make install
Libraries have been installed in : /usr/ local /apr/ lib
============ # 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”
protocol = ” org.apache.coyote.http11.Http11AprProtocol ”
more TOMCAT_HOME/logs/catalina.out 2020-04-17 22:34:56 org.apache.catalina.core.AprLifecycleListener init INFO: Loaded APR based Apache Tomcat Native library 1.1.31 using APR version 1.3.9. 2020-04-17 22:34:56 org.apache.catalina.core.AprLifecycleListener init INFO: APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true]. 2020-04-17 22:34:56 org.apache.catalina.core.AprLifecycleListener initializeSSL INFO: OpenSSL successfully initialized (OpenSSL 1.0.1e 11 Feb 2013) 2020-04-17 22:34:58 AM org.apache.coyote.AbstractProtocol init INFO: Initializing ProtocolHandler [“http-apr-8080”] 2020-04-17 22:34:58 AM org.apache.coyote.AbstractProtocol init INFO: Initializing ProtocolHandler [“ajp-apr-8009”] 2020-04-17 22:34:58 AM org.apache.catalina.startup.Catalina load INFO: Initialization processed in 1125 ms
Tomcat optimization
JAVA_OPTS =-Xms512m -Xmx1024m -XX: PermSize =512M -XX: MaxNewSize =1024m -XX: MaxPermSize =1024m
-Xms: JVM initializes the heap memory size.
-Xmx: The maximum memory of the JVM heap.
-Xss: thread stack size.
-XX:PermSize: The initial memory allocation size of the JVM non-heap area.
-XX:MaxPermSize: The maximum memory of the JVM non-heap area.
JAVA_OPTS =-Xms20480m -Xmx20480m -Xss1024K -XX: PermSize =512m -XX: MaxPermSize =2048m
enableLookups = " false "
<Connector port="8080" protocol=”org.apache.coyote.http11.Http11AprProtocol” connectionTimeout="20000" //Connection timeout redirectPort="8443" maxThreads="500"//Set the maximum number of threads for processing client requests, which determines the number of threads that the server can respond to client requests at the same time, the default is 200 minSpareThreads="20"//Initialize the number of threads, the minimum number of idle threads, the default is 10 acceptCount="1000" //When all available threads for processing requests are used, the number of requests that can be placed in the processing queue, requests exceeding this number will not be processed, the default is 100 enableLookups="false" URIEncoding="UTF-8" />
0 Comments