菜单

Tomcat性能优化

2018年11月16日 - LINUX
首先当然得安装APR,过程可以参考:http://www.cnblogs.com/hackyo/p/6792349.html

注意:如果使用nginx负载均衡的话,请关闭nginx或tomcat其中一个的gzip功能,否则报错
tomcat关闭gzip去掉配置中的下面三行即可。

compression="on" compressionMinSize="1024"
noCompressionUserAgents="gozilla, traviata"
compressableMimeType="text/html,text/xml,text/javascript,text/css,text/plain"


//在tomcat/bin/catalina.sh中加入,如果是windows系统将export改为set并去掉后面值的双引号
export JAVA_OPTS="-server -Xms1000M -Xmx1000M -Xss512k -XX:+AggressiveOpts -XX:+UseBiasedLocking -XX:+DisableExplicitGC -XX:MaxTenuringThreshold=15 -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:+CMSParallelRemarkEnabled -XX:+UseCMSCompactAtFullCollection -XX:LargePageSizeInBytes=128m -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -Djava.awt.headless=true"

//在tomcat/conf/server.xml配置端口,如果没有配置APR则将protocol设置为HTTP/1.1
    <Connector port="80" protocol="org.apache.coyote.http11.Http11AprProtocol"
               maxHttpHeaderSize="8192" maxThreads="1000"
               minSpareThreads="100" maxSpareThreads="1000"
               minProcessors="100" maxProcessors="1000"
               enableLookups="false"
               compression="on" compressionMinSize="1024"
               noCompressionUserAgents="gozilla, traviata"
               compressableMimeType="text/html,text/xml,text/javascript,text/css,text/plain"
               connectionTimeout="25000" URIEncoding="UTF-8"
               acceptCount="1000" redirectPort="443"
               disableUploadTimeout="true" />

//SSL端口配置(使用APR的情况下)
    <Connector port="443" protocol="org.apache.coyote.http11.Http11AprProtocol"
               maxHttpHeaderSize="8192" maxThreads="1000"
               minSpareThreads="100" maxSpareThreads="1000"
               minProcessors="100" maxProcessors="1000"
               enableLookups="false"
               compression="on" compressionMinSize="1024"
               noCompressionUserAgents="gozilla, traviata"
               compressableMimeType="text/html,text/xml,text/javascript,text/css,text/plain"
               connectionTimeout="25000" URIEncoding="UTF-8"
               acceptCount="1000" disableUploadTimeout="true"
               SSLEnabled="true" >
        <UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol" />
        <SSLHostConfig>
            <Certificate certificateKeyFile="conf/cert.key"
                         certificateFile="conf/cert.crt"
                         certificateChainFile="conf/root.crt"
                         type="RSA" />
        </SSLHostConfig>
    </Connector>

//SSL端口配置(不使用APR的情况下)
    <Connector port="443" protocol="HTTP/1.1"
               maxHttpHeaderSize="8192" maxThreads="1000"
               minSpareThreads="100" maxSpareThreads="1000"
               minProcessors="100" maxProcessors="1000"
               enableLookups="false"
               compression="on" compressionMinSize="1024"
               noCompressionUserAgents="gozilla, traviata"
               compressableMimeType="text/html,text/xml,text/javascript,text/css,text/plain"
               connectionTimeout="25000" URIEncoding="UTF-8"
               acceptCount="1000" disableUploadTimeout="true"
               SSLEnabled="true" >
        <SSLHostConfig>
            <Certificate certificateKeystoreFile="conf/cert.jks"
                         certificateKeystorePassword="证书密码"
                         certificateKeyAlias="证书别名"
                         type="RSA" />
        </SSLHostConfig>
    </Connector>
首先当然得安装APR,过程可以参考:http://www.cnblogs.com/hackyo/p/6792349.html

注意:如果使用nginx负载均衡的话,请关闭nginx或tomcat其中一个的gzip功能,否则报错
tomcat关闭gzip去掉配置中的下面三行即可。

compression="on" compressionMinSize="1024"
noCompressionUserAgents="gozilla, traviata"
compressableMimeType="text/html,text/xml,text/javascript,text/css,text/plain"


//在tomcat/bin/catalina.sh中加入,如果是windows系统将export改为set并去掉后面值的双引号
export JAVA_OPTS="-server -Xms1000M -Xmx1000M -Xss512k -XX:+AggressiveOpts -XX:+UseBiasedLocking -XX:+DisableExplicitGC -XX:MaxTenuringThreshold=15 -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:+CMSParallelRemarkEnabled -XX:+UseCMSCompactAtFullCollection -XX:LargePageSizeInBytes=128m -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -Djava.awt.headless=true"

//在tomcat/conf/server.xml配置端口,如果没有配置APR则将protocol设置为HTTP/1.1
    <Connector port="80" protocol="org.apache.coyote.http11.Http11AprProtocol"
               maxHttpHeaderSize="8192" maxThreads="1000"
               minSpareThreads="100" maxSpareThreads="1000"
               minProcessors="100" maxProcessors="1000"
               enableLookups="false"
               compression="on" compressionMinSize="1024"
               noCompressionUserAgents="gozilla, traviata"
               compressableMimeType="text/html,text/xml,text/javascript,text/css,text/plain"
               connectionTimeout="25000" URIEncoding="UTF-8"
               acceptCount="1000" redirectPort="443"
               disableUploadTimeout="true" />

//SSL端口配置(使用APR的情况下)
    <Connector port="443" protocol="org.apache.coyote.http11.Http11AprProtocol"
               maxHttpHeaderSize="8192" maxThreads="1000"
               minSpareThreads="100" maxSpareThreads="1000"
               minProcessors="100" maxProcessors="1000"
               enableLookups="false"
               compression="on" compressionMinSize="1024"
               noCompressionUserAgents="gozilla, traviata"
               compressableMimeType="text/html,text/xml,text/javascript,text/css,text/plain"
               connectionTimeout="25000" URIEncoding="UTF-8"
               acceptCount="1000" disableUploadTimeout="true"
               SSLEnabled="true" >
        <UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol" />
        <SSLHostConfig>
            <Certificate certificateKeyFile="conf/cert.key"
                         certificateFile="conf/cert.crt"
                         certificateChainFile="conf/root.crt"
                         type="RSA" />
        </SSLHostConfig>
    </Connector>

//SSL端口配置(不使用APR的情况下)
    <Connector port="443" protocol="HTTP/1.1"
               maxHttpHeaderSize="8192" maxThreads="1000"
               minSpareThreads="100" maxSpareThreads="1000"
               minProcessors="100" maxProcessors="1000"
               enableLookups="false"
               compression="on" compressionMinSize="1024"
               noCompressionUserAgents="gozilla, traviata"
               compressableMimeType="text/html,text/xml,text/javascript,text/css,text/plain"
               connectionTimeout="25000" URIEncoding="UTF-8"
               acceptCount="1000" disableUploadTimeout="true"
               SSLEnabled="true" >
        <SSLHostConfig>
            <Certificate certificateKeystoreFile="conf/cert.jks"
                         certificateKeystorePassword="证书密码"
                         certificateKeyAlias="证书别名"
                         type="RSA" />
        </SSLHostConfig>
    </Connector>

 

 

相关文章

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图