- 安裝AB
rpm -ivh http://repo.webtatic.com/yum/centos/5/`uname -i`/webtatic-release-5-0.noarch.rpm
yum install httpd-tools
- 使用AB
ab -r -n 100000 -c 10000 http://10.120.151.223:8080/
需加-r,則在收到SOCKET錯(cuò)誤的時(shí)候不會(huì)退出
這段的意思是發(fā)送100000個(gè)請(qǐng)求,其中并發(fā)是10000個(gè)
- 修改LINUX能打開(kāi)的文件的最大數(shù)
2、 修改目標(biāo)
我們的目標(biāo)是:讓每一個(gè)用戶登錄系統(tǒng)后系統(tǒng)打開(kāi)的最大文件數(shù)都是我們?cè)O(shè)定好的。
但我這里不得不說(shuō)的是:非常遺憾,網(wǎng)上很多這方面關(guān)于ulimit設(shè)置修改資源限制的文章,但沒(méi)一篇文章管用。
把這個(gè)目標(biāo)分解為兩個(gè)目標(biāo):
2.1、設(shè)置對(duì)root用戶登錄系統(tǒng)生效
這個(gè)目標(biāo)可以實(shí)現(xiàn)起來(lái)不難
2.2、設(shè)置對(duì)所有用戶生效
這個(gè)就非常麻煩了,弄不好還會(huì)把你的系統(tǒng)給整壞,因?yàn)橐鼐幾gLinux的內(nèi)核才行!
所以權(quán)衡之下,我只實(shí)現(xiàn)了第一個(gè)目標(biāo),因?yàn)榈诙€(gè)目標(biāo)的風(fēng)險(xiǎn)太大,我想如果我之前知道這點(diǎn),那么我在裝系統(tǒng)的時(shí)候我會(huì)先做這個(gè)處理,但現(xiàn)在我覺(jué)得已經(jīng)晚了。
3、 修改的地方
3.1、修改/etc/security/limits.conf
通過(guò) vi /etc/security/limits.conf修改其內(nèi)容,在文件最后加入(數(shù)值也可以自己定義):
* soft nofile = 65536
* hard nofile = 65536
root soft nofile 65536
root hard nofile 65536
* 表示該配置對(duì)所有用戶均有效,root用戶要特別加兩行。
3.2、修改/etc/profile
通過(guò)vi /etc/profile修改,在最后加入以下內(nèi)容
ulimit -n 65536
然后重新登錄即可生效了。
說(shuō)明:
其實(shí)只修改/etc/profile就可以生效了,但我還是建議把/etc/security/limits.conf也修改一下。
最后強(qiáng)調(diào)的是,你如果要使得修改對(duì)所有用戶都生效,那么現(xiàn)在看來(lái)你只能重新編譯Linux的內(nèi)核才行。
- 安裝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
- 修改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"/>
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" />
- JVM啟動(dòng)參數(shù)
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 "
參考網(wǎng)址:
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