httperf and autobench in Slax

0

源起

下面內容可能出現之前做過而省略或是疏漏現象,如有問題請告訴我或是參考之前本站的 Native Tomcat in Slax 一文,也許可以找到相關提示。

my_7_crash.svg

網站要掛了嗎 ?

網站的效能往往需要測試才知道可以跑到哪種程度,平常就應該要測看看,在掛掉之前趕快解決。

關於測試工具 httperf 與 autobench 的部份,請閱讀 HTTP performance testing 一文,有非常詳細的內容可以參考,這裡是要轉化為 slax 可以用的 mo,方便在 vmplayer 之中運行。

一開始要做的是取得檔案後開始安裝 httperf 與 autobench 。

checkinstall httperf

  1. cd /mnt/hda1
  2. wget httperf-0.8.tar.gz
  3. uselivemod Official_Development_module_5_1_4.mo
  4. tar zxvf httperf-0.8.tar.gz
  5. cd httperf-0.8
  6. ./configure
  7. make
  8. checkinstall
  9. mv httperf-0.8-i386-1.tgz /mnt/hda1

checkinstall autobench

  1. cd /mnt/hda1
  2. wget autobench-2.1.2.tar.gz
  3. tar zxvf autobench-2.1.2.tar.gz
  4. cd autobench-2.1.2
  5. ./configure
  6. make
  7. checkinstall
  8. mv autobench-2.1.2-i386-1.tgz /mnt/hda1/

開始測試之前需要網站,這裡用本機的 Tomcat 來測。

start tomcat

  1. uselivemod jre-1_5_0_08-linux.mo
  2. uselivemod apache-tomcat-5.5.15.mo
  3. /usr/local/tomcat/bin/startup.sh
  4. netstat -at

httperf first run

第一次跑用比較少的人數,只用 10 個。

httperf—server=192.168.213.131—port=8080—rate=10—num-conns=500

httperf --client=0/1 --server=192.168.213.131 --port=8080 
--uri=/ --rate=10 --send-buffer=4096 --recv-buffer=16384 
--num-conns=500 --num-calls=1

Maximum connect burst length: 1

Total: connections 500 requests 500 replies 500 test-duration 49.909 s

Connection rate: 10.0 conn/s (99.8 ms/conn, <=2 concurrent connections)
Connection time [ms]: min 1.0 avg 2.0 max 184.5 median 1.5 stddev 8.3
Connection time [ms]: connect 0.0
Connection length [replies/conn]: 1.000

Request rate: 10.0 req/s (99.8 ms/req)
Request size [B]: 66.0

Reply rate [replies/s]: min 10.0 avg 10.0 max 10.0 stddev 0.0 (9 samples)
Reply time [ms]: response 2.0 transfer 0.0
Reply size [B]: header 149.0 content 8132.0 footer 0.0 (total 8281.0)
Reply status: 1xx=0 2xx=500 3xx=0 4xx=0 5xx=0

CPU time [s]: user 0.55 system 48.17 (user 1.1% system 96.5% total 97.6%)
Net I/O: 81.7 KB/s (0.7*10^6 bps)

Errors: total 0 client-timo 0 socket-timo 0 connrefused 0 connreset 0
Errors: fd-unavail 0 addrunavail 0 ftab-full 0 other 0

換個動態 JSP 試看看,加上—uri=/jsp-examples/jsp2/el/basic-arithmetic.jsp 跑起來,沒太大差異,都還沒到瓶頸。

問題在於要找到極限需要不斷加大設定值來測試,手動當然可以,不過這工具已經有人寫好了。

autobench first test

轉用 autobench 來跑多次的結果方便找出掛掉的地方。

autobench --single_host --host1 192.168.213.131 --port1 8080 --uri1 / --quiet \
--low_rate 10 --high_rate 50 --rate_step 10 --num_call 1 \
--num_conn 1000 --timeout 5 --file results.tsv 

結果如下,大致還是可以看出 req_rate 都可以跟上。

dem_req_rate    req_rate_192.168.213.131        con_rate_192.168.213.131       
min_rep_rate_192.168.213.131     avg_rep_rate_192.168.213.131    
max_rep_rate_192.168.213.131    stddev_rep_rate_192.168.213.131 
resp_time_192.168.213.131      net_io_192.168.213.131   errors_192.168.213.131
10      10.0    10.0    10.0    10.0    10.0    0.0     1.1     81.6    0
20      20.0    20.0    20.0    20.0    20.0    0.0     1.1     163.2   0
30      30.0    30.0    30.0    30.0    30.0    0.0     1.0     244.8   0
40      40.0    40.0    40.0    40.0    40.0    0.0     1.1     326.4   0
50      50.0    50.0    50.0    50.0    50.0    0.0     1.0     408.0   0

文字檔很難看出正確的趨勢,還是轉圖出來看比較方便找出關鍵。

download gnuplot

輸出圖案來判讀簡單了解,不過需要先下載 gnuplot mo 來裝。

  1. cd /mnt/hda1
  2. wget gnuplot_4_0.mo
  3. uselivemod gnuplot_4_0.mo

裝好就可以用 bench2graph 跑看看。

bench2png

autobench 附的 bench2graph 會輸出 postscript 格式,這裡換成 PNG 格式。改成 echo set terminal png small color 的命令。

  1. cd /usr/local/bin
  2. cp bench2graph bench2png
  3. vi bench2png
  4. cd to autobench results dir
  5. bench2png results.tsv result.png

上圖可以看到整個線性上升,尚未到底,再加點負荷,跑一次看看,同時為了避免流量飆高,整個 Y 軸都是流量,會導致其他數值看起來躺在 X 軸上,所以採用指定欄位的做法,避掉 net_io 這一欄。

# autobench --single_host --host1 192.168.213.131 --port1 8080 --uri1 / --quiet \
--low_rate 10 --high_rate 100 --rate_step 10 --num_call 10 \
--num_conn 1000 --timeout 5 --file results2.tsv
bench2png results2.tsv results2.png 4 5 6 7 8

圖中可以看到卡在800-900 請求/秒 (80-90 連線/秒) 的時候,急速墜落。

道這裡完成基本安裝與測試,接下來可以包個 mo 出來用了,免得關機完要再來一次。

dir2mo autobench mo

為求以後測試方便,將 httperf 與 autobench 包成一個 mo,同時加上改的 bench2png。

  1. cd /mnt/hda1/work
  2. mkdir autobench
  3. installpkg -root autobench ../autobench-2.1.2-i386-1.tgz
  4. installpkg -root autobench ../httperf-0.8-i386-1.tgz
  5. cp /usr/local/bin/bench2png autobench/usr/local/bin/
  6. dir2mo autobench autobench-2.1.2.mo
  7. reboot for test.

包完後開機一次做完整測試。

uselivemod autobench-2.1.2.mo

  1. cd /mnt/hda1/work
  2. uselivemod jre-1_5_0_08-linux.mo
  3. uselivemod apache-tomcat-5.5.15.mo
  4. uselivemod gnuplot_4_0.mo
  5. uselivemod autobench-2.1.2.mo
  6. /usr/local/tomcat/bin/startup.sh
  7. cd /tmp
  8. autobench again
  9. bench2png results.tsv results.png 4 5 6 7 8

這裡可以用更細的方式試看看,改取每次加五個方式。

autobench --single_host --host1 192.168.213.131 --port1 8080 --uri1 / --quiet \
--low_rate 50 --high_rate 100 --rate_step 5 --num_call 10 \
--num_conn 1000 --timeout 5 --file results.tsv 

看起來 750需求 (75連線) 左右就開始不穩。奇怪的是後來又線性上揚,不清楚是不是 JVM 的 GC 運作導致 Tomcat 一口氣喘不過來,有機會再多做些測試。

download autobench-2.1.2.mo

autobench-2.1.2.mo

links

The Linux HTTP Benchmarking HOWTO

httperf—-A Tool for Measuring Web Server Performance

Comments

(leave url/email »)

   Preview comment