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 閱讀(514) 評論(0)  編輯  收藏 所屬分類: 性能優化TOMCAT

          主站蜘蛛池模板: 吉林市| 龙门县| 梁平县| 九龙城区| 黑河市| 花莲市| 德阳市| 锡林郭勒盟| 祁门县| 博野县| 伊川县| 桑日县| 出国| 胶州市| 修武县| 犍为县| 贵港市| 罗平县| 渝北区| 大关县| 绥江县| 麻城市| 三穗县| 廉江市| 会理县| 双桥区| 安庆市| 高雄县| 马尔康县| 安仁县| 巢湖市| 台东县| 来宾市| 北辰区| 广安市| 昌宁县| 友谊县| 梓潼县| 留坝县| 阿图什市| 枣庄市|