Tomcat性能调优
1、修改JVM参数
在catalina.bat中添加如下配置
set "JAVA_OPTS=%JAVA_OPTS% -server -Xms4096m -Xmx4096m -Xmn2048m -Xss512k -XX:PermSize=128m -XX:MaxPermSize=512m -XX:NewSize=1024m -XX:MaxNewSize=2048m -XX:MaxDirectMemorySize=4096m -XX:ReservedCodeCacheSize=240M -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:MaxTenuringThreshold=15 -XX:+ExplicitGCInvokesConcurrent -XX:+ParallelRefProcEnabled -XX:-UseBiasedLocking -XX:-UseCounterDecay -XX:AutoBoxCacheMax=20000 -XX:+AlwaysPreTouch -XX:-OmitStackTraceInFastThrow -XX:SurvivorRatio=18 -XX:+UseParNewGC -XX:ParallelGCThreads=4 -XX:+CMSParallelRemarkEnabled -XX:+CMSScavengeBeforeRemark -XX:+ScavengeBeforeFullGC -XX:+CMSClassUnloadingEnabled -XX:+PrintGCApplicationConcurrentTime -XX:+PrintHeapAtGC -XX:ErrorFile=../logs/hs_err_%p.log -XX:+PrintGCDateStamps -XX:+PrintGCDetails -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=../logs/ -Xloggc:../logs/gc.log -Djava.awt.headless=true"
2、设置tomcat管控台用户
tomcat-users.xml
<role rolename="admin-gui"/>
<role rolename="manager-gui"/>
<user username="tomcat" password="tomcat" roles="admin-gui,manager-gui"/>
3、修改server.xml
防止tomcat被远程telnet连接导致shutdown修改SHUTDOWN端口
<Server port="-1" shutdown="SHUTDOWN">
开启Apr监听和防止内存泄漏Listener
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
设置tomcat并发及优化线程数
<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
maxThreads="3000" minSpareThreads="1000" maxIdleTime="600000"
prestartminSpareThreads="true" maxQueueSize="2000"/>
<Connector port="8080" protocol="org.apache.coyote.http11.Http11NioProtocol"
executor="tomcatThreadPool"
connectionTimeout="20000"
redirectPort="8443"
URIEncoding="UTF-8"
enableLookups="false"
disableUploadTimeout="true"
maxHttpHeaderSize="8192"
maxConnections="10000"
maxPostSize="10485760"
acceptCount="2000"
acceptorThreadCount="2"
compression="on"
server="Neo App Srv 1.0"
compressionMinSize="2048"
compressableMimeType="text/html,text/xml,text/plain,text/css,text/javascript"/>
org.apache.coyote.http11.Http11NioProtocol
org.apache.coyote.http11.Http11AprProtocol
4、隐藏tomcat版本
修改TOMCAT_HOME\lib\catalina.jar文件中org/apache/catalina/util/ServerInfo.properties文件内容如下
server.info=Apache Tomcat
server.number=0.0.0
server.built=
5、禁用AJP
若不集成Apache建议禁用AJP协议以提升效率
<!-- <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /> -->
https://github.com/ameizi/DevArticles 相关环境集群搭建
转自https://github.com/ameizi/DevArticles/issues/158
1、修改JVM参数
在catalina.bat中添加如下配置
set "JAVA_OPTS=%JAVA_OPTS% -server -Xms4096m -Xmx4096m -Xmn2048m -Xss512k -XX:PermSize=128m -XX:MaxPermSize=512m -XX:NewSize=1024m -XX:MaxNewSize=2048m -XX:MaxDirectMemorySize=4096m -XX:ReservedCodeCacheSize=240M -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:MaxTenuringThreshold=15 -XX:+ExplicitGCInvokesConcurrent -XX:+ParallelRefProcEnabled -XX:-UseBiasedLocking -XX:-UseCounterDecay -XX:AutoBoxCacheMax=20000 -XX:+AlwaysPreTouch -XX:-OmitStackTraceInFastThrow -XX:SurvivorRatio=18 -XX:+UseParNewGC -XX:ParallelGCThreads=4 -XX:+CMSParallelRemarkEnabled -XX:+CMSScavengeBeforeRemark -XX:+ScavengeBeforeFullGC -XX:+CMSClassUnloadingEnabled -XX:+PrintGCApplicationConcurrentTime -XX:+PrintHeapAtGC -XX:ErrorFile=../logs/hs_err_%p.log -XX:+PrintGCDateStamps -XX:+PrintGCDetails -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=../logs/ -Xloggc:../logs/gc.log -Djava.awt.headless=true"
2、设置tomcat管控台用户
tomcat-users.xml
<role rolename="admin-gui"/>
<role rolename="manager-gui"/>
<user username="tomcat" password="tomcat" roles="admin-gui,manager-gui"/>
3、修改server.xml
防止tomcat被远程telnet连接导致shutdown修改SHUTDOWN端口
<Server port="-1" shutdown="SHUTDOWN">
开启Apr监听和防止内存泄漏Listener
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
设置tomcat并发及优化线程数
<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
maxThreads="3000" minSpareThreads="1000" maxIdleTime="600000"
prestartminSpareThreads="true" maxQueueSize="2000"/>
<Connector port="8080" protocol="org.apache.coyote.http11.Http11NioProtocol"
executor="tomcatThreadPool"
connectionTimeout="20000"
redirectPort="8443"
URIEncoding="UTF-8"
enableLookups="false"
disableUploadTimeout="true"
maxHttpHeaderSize="8192"
maxConnections="10000"
maxPostSize="10485760"
acceptCount="2000"
acceptorThreadCount="2"
compression="on"
server="Neo App Srv 1.0"
compressionMinSize="2048"
compressableMimeType="text/html,text/xml,text/plain,text/css,text/javascript"/>
org.apache.coyote.http11.Http11NioProtocol
org.apache.coyote.http11.Http11AprProtocol
4、隐藏tomcat版本
修改TOMCAT_HOME\lib\catalina.jar文件中org/apache/catalina/util/ServerInfo.properties文件内容如下
server.info=Apache Tomcat
server.number=0.0.0
server.built=
5、禁用AJP
若不集成Apache建议禁用AJP协议以提升效率
<!-- <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /> -->
https://github.com/ameizi/DevArticles 相关环境集群搭建
转自https://github.com/ameizi/DevArticles/issues/158