paulwong

TOMCAT调优

  1. 安装AB
    rpm -ivh http://repo.webtatic.com/yum/centos/5/`uname -i`/webtatic-release-5-0.noarch.rpm
    yum install httpd-tools

  2. 使用AB
    ab -r -n 100000 -c 10000 http://10.120.151.223:8080/
    需加-r,则在收到SOCKET错误的时候不会退出
    这段的意思是发送100000个请求,其中并发是10000个

  3. 修改LINUX能打开的文件的最大数
    2、  修改目标
    我们的目标是:让每一个用户登录系统后系统打开的最大文件数都是我们设定好的。
    但我这里不得不说的是:非常遗憾,网上很多这方面关于ulimit设置修改资源限制的文章,但没一篇文章管用。
    把这个目标分解为两个目标:

    2.1、设置对root用户登录系统生效
    这个目标可以实现起来不难

    2.2、设置对所有用户生效
    这个就非常麻烦了,弄不好还会把你的系统给整坏,因为要重编译Linux的内核才行!
    所以权衡之下,我只实现了第一个目标,因为第二个目标的风险太大,我想如果我之前知道这点,那么我在装系统的时候我会先做这个处理,但现在我觉得已经晚了。

    3、  修改的地方

    3.1、修改/etc/security/limits.conf
    通过 vi /etc/security/limits.conf修改其内容,在文件最后加入(数值也可以自己定义):
    * soft  nofile = 65536
    * hard  nofile = 65536
    root soft nofile 65536
    root hard nofile 65536
    * 表示该配置对所有用户均有效,root用户要特别加两行。

    3.2、修改/etc/profile
    通过vi /etc/profile修改,在最后加入以下内容
    ulimit -n 65536
    然后重新登录即可生效了。
    说明:
    其实只修改/etc/profile就可以生效了,但我还是建议把/etc/security/limits.conf也修改一下。
    最后强调的是,你如果要使得修改对所有用户都生效,那么现在看来你只能重新编译Linux的内核才行。


  4. 安装APR,参考:http://jmchung.github.io/blog/2013/09/06/centos-installing-apache-portable-runtime-apr-for-tomcat/
    $ wget http://apache.fayea.com//apr/apr-1.5.1.tar.gz
    $ cd /path/to/tomcat/bin
    $ tar zxvf tomcat-native.tar.gz
    $ cd tomcat-native-x.y.z-src/jni/native
    $ ./configure --with-apr=/usr/local/apr --with-ssl=/usr/lib64/openssl
    $ make install

  5. 修改server.xml
    <Connector port="8080" protocol="org.apache.coyote.http11.Http11AprProtocol"
            URIEncoding
    ="UTF-8"  
                  enableLookups
    ="false" 
                  tcpNoDelay
    ="true"
            compression
    ="on" compressionMinSize="2048"
            maxThreads
    ="20000" connectionTimeout="-1"
            compressableMimeType
    ="application/json,text/html,text/xml,text/javascript,text/css,text/plain" redirectPort="8443"/>


  6. https的也要修改:
    <Connector SSLEnabled="true" clientAuth="false"
            port
    ="8443" keystoreFile="/root/java/keystore/server.jks" keystorePass="123456"
            protocol
    ="org.apache.coyote.http11.Http11NioProtocol" scheme="https"
            secure
    ="true" sslProtocol="TLS" 
        URIEncoding
    ="UTF-8"  minSpareThreads="25" maxSpareThreads="75"
               enableLookups
    ="false" disableUploadTimeout="true" connectionTimeout="20000"
        acceptCount
    ="1000"  maxThreads="1000" maxProcessors="1000" minProcessors="5"
        useURIValidationHack
    ="false" tcpNoDelay="true"
        compression
    ="on" compressionMinSize="2048"
        compressableMimeType
    ="application/json,text/html,text/xml,text/javascript,text/css,text/plain" />

  7. JVM启动参数
    JAVA_OPTS="-server -Xms2048m -Xmx2048m -Xss512k -XX:+AggressiveOpts -XX:+UseBiasedLocking -XX:PermSize=128M -XX:MaxPermSize=256M -XX:+DisableExplicitGC -XX:MaxTenuringThreshold=31 -XX:+UseConcMarkSweepGC -XX:+UseParNewGC  -XX:+CMSParallelRemarkEnabled -XX:+UseCMSCompactAtFullCollection -XX:LargePageSizeInBytes=128m  -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly -Djava.awt.headless=true "

参考网址:
http://www.cnblogs.com/baibaluo/archive/2011/08/23/2150305.html
http://ifeve.com/tomcat-connector-tuning-2/
http://sndapk.blog.51cto.com/5385144/1306278

posted on 2015-01-06 17:40 paulwong 阅读(493) 评论(0)  编辑  收藏 所属分类: 性能优化TOMCAT


只有注册用户登录后才能发表评论。


网站导航: