提高Tomcat性能
1, ab - Apache HTTP server benchmarking tool
? 安裝 Apatch2 之后,在 bin 目錄下有這個命令,在控制臺上運行 ab, 就可以看到幫助內容,大體如下:
D:\Apache2\bin>ab ab: wrong number of arguments Usage: ab [options] [http://]hostname[:port]/path Options are: ??? -n requests???? Number of requests to perform ??? -c concurrency? Number of multiple requests to make ??? -t timelimit??? Seconds to max. wait for responses ??? -p postfile???? File containing data to POST ??? -T content-type Content-type header for POSTing ??? -v verbosity??? How much troubleshooting info to print ??? -w????????????? Print out results in HTML tables ??? -i????????????? Use HEAD instead of GET ??? -x attributes?? String to insert as table attributes ??? -y attributes?? String to insert as tr attributes ??? -z attributes? ?String to insert as td or th attributes ??? -C attribute??? Add cookie, eg. 'Apache=1234. (repeatable) ??? -H attribute??? Add Arbitrary header line, eg. 'Accept-Encoding: gzip' ??????????????????? Inserted after all normal header lines. (repeatable) ??? -A attribute??? Add Basic WWW Authentication, the attributes ??????????????????? are a colon separated username and password. ??? -P attribute??? Add Basic Proxy Authentication, the attributes ??????????????????? are a colon separated username and password. ??? -X proxy:port?? Proxyserver and port number to use ??? -V????????????? Print version number and exit ??? -k????????????? Use HTTP KeepAlive feature ??? -d????????????? Do not show percentiles served table. ??? -S????????????? Do not show confidence estimators and warnings. ??? -g filename???? Output collected data to gnuplot format file. ??? -e filename???? Output CSV file with percentages served ??? -h????????????? Display usage information (this message) |
顯然 n 和 c 是最重要的兩個選項。
2,Apache-JMeter
?????? JMeter 是 Apache 開源項目里的一個單獨項目,功能比較全面,解壓縮之后可以閱讀文檔。測試 web 的順序是先建立線程組,再建立 Http 請求,最后建立 2 個觀察結果的項:用表格和 summary report.
二, 測試過程:
環境:內存
我要壓力測試代表性頁面: http://61.172.192.35/nrc/publik/demo/customers.htm 這個頁面查詢 500 條記錄, 并且在頁面上顯示 100 條記錄。
并發線程數: 20
共訪問次數: 1000
測試之前,
1,?
在
JVM
級別上做優化,修改了
catalina.bat
文件中
-Xms
和
–Xmx
兩個參數,一般設置為內存的
80%
,因為機器內存是
1GB,
所以,改為:
?-Xms
2,? 禁止 Tomcat 的 DNS 解析,其實 Tomcat 默認就是禁止解析的。
用
ab
進行測試:
命令: D:\Apache2\bin>ab -c 20 -n 1000 http://61.172.192.35/snrc/publik/demo/customers.htm >> d:\stress.txt
未啟用 APR 之前,運行結果如下:
Server Software:??????? Apache-Coyote/1.1 Server Hostname:??????? 61.172.192.35
Document Path:????????? /nrc/publik/demo/customers.htm Document Length:??????? 3277 bytes
Concurrency Level:????? 20 Time taken for tests:?? 601.328125 seconds Complete requests:????? 1000 Failed requests:??????? 999 ?? (Connect: 0, Length: 999, Exceptions: 0) Write errors:?????????? 0 Non-2xx responses:????? 16 Total transferred:????? 73815422 bytes HTML transferred:?????? 73541950 bytes Requests per second:??? 1.66 [#/sec] (mean) Time per request:?????? 12026.563 [ms] (mean) Time per request:?????? 601.328 [ms] (mean, across all concurrent requests) Transfer rate:????????? 119.88 [Kbytes/sec] received
Connection Times (ms) ????????????? min? mean[+/-sd] median?? max Connect:??????? 0??? 2?? 5.3????? 0????? 31 Processing:? 1265 11946 14632.7?? 9859? 121656 Waiting:????? 640 8245 14931.0?? 6421? 121656 Total:?????? 1265 11948 14633.1?? 9859? 121671
Percentage of the requests served within a certain time (ms) ? 50%?? 9859 ? 66%? 10515 ? 75%? 10937 ? 80%? 11343 ? 90%? 12796 ? 95%? 14921 ? 98%? 57359 ? 99%? 119890 ?100%? 121671 (longest request) |
啟用 APR 之后的結果:
Server Software:??????? Apache-Coyote/1.1 Server Hostname:??????? 61.172.192.35
Document Path:????????? /nrc/publik/demo/customers.htm Document Length:??????? 74705 bytes
Concurrency Level:????? 20 Time taken for tests:?? 601.500000 seconds Complete requests:????? 1000 Failed requests:??????? 911 ?? (Connect: 0, Length: 911, Exceptions: 0) Write errors:?????????? 0 Non-2xx responses:????? 16 Total transferred:????? 73808906 bytes HTML transferred:?????? 73535578 bytes Requests per second:??? 1.66 [#/sec] (mean) Time per request:?????? 12030.000 [ms] (mean) Time per request:?????? 601.500 [ms] (mean, across all concurrent requests) Transfer rate:????????? 119.83 [Kbytes/sec] received
Connection Times (ms) ??????????? ??min? mean[+/-sd] median?? max Connect:??????? 0??? 1?? 5.1????? 0????? 31 Processing:? 3703 11952 15032.6?? 9375? 120593 Waiting:????? 593 7073 15476.2?? 4906? 120593 Total:?????? 3703 11954 15032.5?? 9375? 120593
Percentage of the requests served within a certain time (ms) ? 50%?? 9375 ? 66%? 10250 ? 75%? 11093 ? 80%? 11687 ? 90%? 13734 ? 95%? 15750 ? 98%? 70812 ? 99%? 119937 ?100%? 120593 (longest request) |
用 JMeter 進行測試:
下栽 tcnative-1.dll ,放在 tomcat/apr/tcnative-1.dll, 修改 catalina.bat 中 JAVA_OPTS ?-Djava.library.path="%CATALINA_BASE%\arp"
未啟用
APR,
結果如下:
起用
APR,
結果如下:
對比兩個結果,啟動 APR ,效果并不十分明顯。可能做 load balance 效果會更明顯。
三, 解決辦法總結:
1,? 優化 JVM 的內存數量;
2,? 禁止 DNS 解析;
3,? 啟用 APR ;
是否啟動了 APR ? 在 Tomcat 啟動之后,看到:xxxxx http11BaseProtocol Start 表示沒有啟用 APR
xxxxx http11AprProtocol Star 表示啟用了 APR
四, 待續
用一個 Apache2 + 2 個 Tomcat 在一臺服務器上做負載均衡。
posted on 2006-12-11 19:32 MingIsMe 閱讀(268) 評論(0) 編輯 收藏 所屬分類: 06 J2EE