该优化针对Linux X86_X64环境

http://netkiller.github.io/www/tomcat/server.html

1. Tomcat优化其实就是对server.xml优化(开户线程池,调整http connector参数)

搜索【<Executor name="tomcatThreadPool"】,开启并调整为
<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
        maxThreads="1000" maxIdleTime="60000"
        minSpareThreads="20"/>
搜索【port="8080"】,调整为
<Connector executor="tomcatThreadPool" port="8080" //开启线程池
    protocol="org.apache.coyote.http11.Http11AprProtocol"//开启Apr协议,需要安装Apr支持
     maxHttpHeaderSize="8192" maxThreads="1000" processorCache="1000" acceptCount="1000"
    minSpareThreads="100"
    acceptorThreadCount="8" URIEncoding="UTF-8"
     enableLookups="false" redirectPort="8443"//关闭反向查询
     connectionTimeout="120000" keepAliveTimeout="120000"
     maxKeepAliveRequests="65535" disableUploadTimeout="true"
     compression="on" compressionMinSize="4096"//开启静态文件压缩
     noCompressionUserAgents="gozilla, traviata"//开启静态文件压缩
     compressableMimeType="text/html,text/xml,text/javascript,text/css,text/plain,application/json,application/x-javascript " //开启静态文件压缩
/>

2. 对catalina.sh优化JVM

打开 Tomcat路径\bin\ catalina.sh,在最顶部加入,红色部分请根据实际情况调整
JAVA_OPTS="-server -showversion -Xms12g -Xmx12g -XX:PermSize=256m -XX:MaxPermSize=256m"
JAVA_OPTS="$JAVA_OPTS -d64 -XX:CICompilerCount=8 -XX:+UseCompressedOops"
JAVA_OPTS="$JAVA_OPTS -XX:SurvivorRatio=4 -XX:TargetSurvivorRatio=90"
JAVA_OPTS="$JAVA_OPTS -XX:ReservedCodeCacheSize=256m -XX:-UseAdaptiveSizePolicy"
JAVA_OPTS="$JAVA_OPTS -Duser.timezone=Asia/Shanghai -XX:-DontCompileHugeMethods"
JAVA_OPTS="$JAVA_OPTS -Xss256k -XX:+AggressiveOpts -XX:+UseBiasedLocking"
JAVA_OPTS="$JAVA_OPTS -XX:MaxTenuringThreshold=31 -XX:+CMSParallelRemarkEnabled "
JAVA_OPTS="$JAVA_OPTS -XX:+UseCMSCompactAtFullCollection -XX:LargePageSizeInBytes=256m -XX:+UseFastAccessorMethods"
JAVA_OPTS="$JAVA_OPTS -XX:+UseCMSInitiatingOccupancyOnly -Djava.awt.headless=true"
JAVA_OPTS="$JAVA_OPTS -XX:+UseGCOverheadLimit -XX:AllocatePrefetchDistance=256 -XX:AllocatePrefetchStyle=1"
JAVA_OPTS="$JAVA_OPTS -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:MaxGCPauseMillis=200"
【注意】
1.-Xms=-Xmx=服务器内存*70%,如部署tomcat,jboss在同一台服务器-Xms=-Xmx=服务器内存*80%*1/4

2. 添加的参数建议要自己明白是什么意思,可以参考JVM参数列表

你可能感兴趣的:(linux)