Tomcat8 concurrency Optimization

Source: Internet
Author: User
Tags log log apache tomcat redis cluster
1. Tomcat JVM Optimization

See JVM optimization for details

http://blog.csdn.net/sinlff/article/details/62038816

2. Tomcat thread pool
Tomcat_home/conf/server.xml
Name: The thread pool names, which are specified in connector.
Nameprefix: The name prefix of each thread created, and a separate thread name is Nameprefix+threadnumber.
MaxThreads: The maximum number of threads in the pool.
Minsparethreads: The number of active threads, that is, the number of core pool threads, which are not destroyed and will always exist.
MaxIdleTime: Thread idle time, after which the idle thread is destroyed, with a default value of 6000 (1 minutes), in milliseconds.
Maxqueuesize: The maximum number of thread queues before being executed, the default is the maximum value of int, which is the infinity of the generalized. Unless this is a special case, the value does not need to be changed, otherwise a request will not be processed.
Prestartminsparethreads: Whether to start a minsparethreads portion of threads when the thread pool is started. The default value is False, which is not started.
ThreadPriority: Thread pool threads priority, default value is 5, value from 1 to 10.
ClassName: Thread pool Implementation class, not specified, the default implementation class is Org.apache.catalina.core.StandardThreadExecutor. If you want to use a custom thread pool, you first need to implement the Org.apache.catalina.Executor interface.
After the thread pool configuration is complete, you need to specify in connector


3, Tomcat concurrent Connector, parameter explanation http://1632004.blog.163.com/blog/static/29991497201201912858468/official website parameter explanation http:// Tomcat.apache.org/tomcat-7.0-doc/config/http.html
Org.apache.coyote.http11.Http11NioProtocol
Org.apache.coyote.http11.Http11AprProtocol
KeepAliveTimeout-Indicates how long the tomcat will remain connected until the next request comes. This means that if the client continues to have requests and does not exceed the expiration time, the connection is maintained.
Maxkeepaliverequests-Represents the maximum number of requests that this connection supports. Connections exceeding the number of requests will also be closed (a connection:close header is returned to the client at this point). (maxkeepaliverequests= "1" stands for disabling long connections) (1 for disabling,-1 for unlimited numbers, and 100 for default). The general setting is between 100~200) the maximum number of HTTP requests that can was held in the pipeline until the connection was closed by the Server. Setting this attribute to 1 disables http/1.0 keep-alive, as as the http/1.1 keep-alive and pipelining. Setting This to-1 allows a unlimited number of pipelined or keep-alive HTTP requests. If not specified, the This attribute was set to 100.
Maxqueuesize: The maximum number of thread queues before being executed, the default is the maximum value of int, which is the infinity of the generalized. Unless this is a special case, the value does not need to be changed, otherwise a request will not be processed.
Acceptcount: The maximum queue length for incoming connection requests when all possible request processing threads are in use. If not specified, the default value is 100. Typically set to the same or half as maxthreads, this value is set over the assembly that causes the queued request to time out and is not processed. So this value should be based primarily on the application's peak of access and average to weigh the configuration.
Response packet Compression compression= "on"


<executor name= "Tomcatthreadpool" nameprefix= "catalina-exec-" maxthreads= "3000" minsparethreads= "500" Maxidletime= "180000" prestartminsparethreads= "true" threadpriority= "5"/>
<connector port= "8080" protocol= "Org.apache.coyote.http11.Http11AprProtocol"
Connectiontimeout= "30000" asynctimeout= "30000" keepalivetimeout= "10000" maxkeepaliverequests= "200"
Executor= "Tomcatthreadpool" maxconnections= "3000" acceptcount= "3000"
Acceptorthreadcount= "4" acceptorthreadpriority= "5"
Maxhttpheadersize= "4096" socketbuffer= "10240"
Sslenabled= "false" uriencoding= "UTF-8" usebodyencodingforuri= "true" tcpnodelay= "true" enablelookups= "false" Disableuploadtimeout= "true"
compression= "Off" compressionminsize= "nocompressionuseragents=" Gozilla,traviata "compressablemimetype=" text/ Html,text/xml,text/javascript,application/javascript,text/css,text/plain,application/json "/>

Maxsparethreads the largest unused request processing thread that exists before the online pool starts stopping unnecessary threads
Acceptcount the maximum length of the connection request queue when all possible request processing threads are used. If the team is full, all requests are rejected and the default value is 10. (not less than maxsparethreads)
Maxkeepaliverequests maximum number of long connections (1 for disabled, 1 for unlimited, 100 for default)
KeepAliveTimeout Long Connection Timeout
Enablelookups if set to True, support domain name resolution, IP address can be resolved to host name
Redirectport forward customer requests to SSL based Redirectport ports where security channels are needed


4. Turn off Tomcat's extra log
Tomcat_home/conf/server.xml-> <valve classname= "Org.apache.catalina.valves.AccessLogValve" commented out
Tomcat_home/conf/logging.properties-> Handlers=java.util.logging.consolehandler, modify log log to point to path


5, APR I/O

Tomcat8/conf/server.xml Release Notes
<listener sslengine= "on" classname= "Org.apache.catalina.core.AprLifecycleListener"/> Apr, apr-util, native
Apr (Apache portable Runtime/apache Portable runtime) is the support library for Apache HTTP servers. You can simply understand that Tomcat will invoke the core dynamic link Library of the Apache HTTP server as JNI to handle file read or network transfer operations
, which greatly improves the processing performance of Tomcat to static files.
The Tomcat APR is also the preferred mode for running high concurrent applications on Tomcat.
Tomcat-native.tar.gz can be found in the Tomcat/bin directory
Windows installation:
Http://www.blogjava.net/tinguo002/archive/2014/07/17/415939.html?utm_source=tuicool
Step one: Tcnative-1.dll into the Tomcat/bin directory
Step Two: Windows environment variable path increase; D:\soft\tomcat7\bin
Step three: Protocol= "Org.apache.coyote.http11.Http11AprProtocol"


Linux Installation:
http://blog.csdn.net/god123209/article/details/8784289
Startup does not report a hint, indicating that the APR plugin has been installed
April 7:19:34 PM Org.apache.catalina.core.AprLifecycleListener Init
Info:the APR based Apache Tomcat Native Library which allows optimal performance in production environments is not found On the Java.library.path:/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
(1) Installation of Apr tomcat-native
Apr-1.3.8.tar.gz installed in/USR/LOCAL/APR
#tar ZXVF apr-1.3.8.tar.gz
#cd apr-1.3.8
#./configure;make;make Install

Apr-util-1.3.9.tar.gz installed in/usr/local/apr/lib
#tar ZXVF apr-util-1.3.9.tar.gz
#cd apr-util-1.3.9
#./configure--WITH-APR=/USR/LOCAL/APR----With-java-home=jdk;make;make Install

#cd Apache-tomcat-6.0.20/bin
#tar ZXVF tomcat-native.tar.gz
#cd tomcat-native/jni/native
#./configure--with-apr=/usr/local/apr;make;make Install

(2) Set up Tomcat integration APR
Modify Tomcat's startup Shell (startup.sh) to include the startup parameters in the file:
catalina_opts= "$CATALINA _opts-djava.library.path=/usr/local/apr/lib".


(3) To determine the installation success:
If you see the following startup log, this indicates success.
Org.apache.coyote.http11.Http11AprProtocol Init
Loaded APR based Apache Tomcat Native Library
Starting Protocolhandler ["Http-apr


6, set session expiration time, Redis cluster conversation sharing: Tomcat_home/conf/context.xml-> Valve Manager Sessions Redis
Tomcat8/conf/context.xml
<valve classname= "Com.radiadesign.catalina.session.RedisSessionHandlerValve"/>
<manager classname= "Com.radiadesign.catalina.session.RedisSessionManager"
Expiresessionsecond= "604800"
Iscluster= "false"
redisinfo= "172.16.1.19:6381"
Redispwd= ""
Appid= "10000"
Minidle= "5"
minevictableidletimemillis= "1500"
Maxidle= "10"
Maxtotal= "30"
Maxwaitmillis= "3000"
Testonborrow= "true"/>

7, turn off the automatic deployment function
To
Autodeploy= "false"

8, turn off automatic hot update reloadable= "false"
Server.xml <Context> deployment, setting reloadable= "false"

9, prohibit Tomcat scan jar package of TLD file,
Tomcat/conf/logging.properties Uncomment Org.apache.jasper.compiler.tldlocationscache.level=fine
Tomcat/conf/catalina.properties Modify Tomcat.util.scan.standardjarscanfilter.jarstoskip=*.jar
Server.xml Open <listener classname= "Org.apache.catalina.core.AprLifecycleListener" sslengine= "on"/>


10, JSP development set to FALSE, or checkinterval configure the trigger frequency of background compilation
Genstringaschararray=true
Trimspace=true
Enablepooling=true
JSP Tag Pool


11, increase the TCP connection kernel parameters: the maximum number of connections allowed by Web server is also subject to the operating system kernel parameter settings, usually Windows is about 2000, Linux is about 1000.


12. Integration with Web server
12.1, Nginx realize keep-alive keepalivetimeout= "8000" maxkeepaliverequests= "50"
12.2, NGINX-SSL support
12.3, processing static files

13, Nginx_ajp_mode
Nginx AJP Tomcat

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.