<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Extreme Pattern: httperf and autobench in Slax</title>
    <link>http://blog.extremepattern.com/articles/2006/09/13/httperf-and-autobench-in-slax</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>enjoy</description>
    <item>
      <title>httperf and autobench in Slax</title>
      <description>&lt;h3&gt;源起&lt;/h3&gt;


	&lt;p&gt;下面內容可能出現之前做過而省略或是疏漏現象，如有問題請告訴我或是參考之前本站的 &lt;a href="/articles/2006/09/11/native-tomcat-in-slax"&gt;Native Tomcat in Slax&lt;/a&gt;  一文，也許可以找到相關提示。&lt;/p&gt;


	&lt;p&gt;&lt;img src="/files/my_7_crash.png" alt="" /&gt;&lt;/p&gt;


	&lt;p&gt;&lt;img src="/files/archive.png" alt="" /&gt; &lt;a href="/files/my_7_crash.svg"&gt;my_7_crash.svg&lt;/a&gt;&lt;/p&gt;


	&lt;h3&gt;網站要掛了嗎 ?&lt;/h3&gt;


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


	&lt;p&gt;關於測試工具 httperf 與 autobench 的部份，請閱讀 &lt;a href="http://agiletesting.blogspot.com/2005/04/http-performance-testing-with-httperf.html"&gt;&lt;span class="caps"&gt;HTTP&lt;/span&gt; performance testing&lt;/a&gt; 一文，有非常詳細的內容可以參考，這裡是要轉化為 slax 可以用的 mo，方便在 vmplayer 之中運行。&lt;/p&gt;


	&lt;p&gt;一開始要做的是取得檔案後開始安裝 httperf 與 autobench 。&lt;/p&gt;


	&lt;h3&gt;checkinstall httperf&lt;/h3&gt;


	&lt;ol&gt;
	&lt;li&gt;cd /mnt/hda1&lt;/li&gt;
		&lt;li&gt;wget httperf-0.8.tar.gz&lt;/li&gt;
		&lt;li&gt;uselivemod Official_Development_module_5_1_4.mo&lt;/li&gt;
		&lt;li&gt;tar zxvf httperf-0.8.tar.gz&lt;/li&gt;
		&lt;li&gt;cd httperf-0.8&lt;/li&gt;
		&lt;li&gt;./configure&lt;/li&gt;
		&lt;li&gt;make&lt;/li&gt;
		&lt;li&gt;checkinstall&lt;/li&gt;
		&lt;li&gt;mv httperf-0.8-i386-1.tgz /mnt/hda1&lt;/li&gt;
	&lt;/ol&gt;


	&lt;h3&gt;checkinstall autobench&lt;/h3&gt;


	&lt;ol&gt;
	&lt;li&gt;cd /mnt/hda1&lt;/li&gt;
		&lt;li&gt;wget autobench-2.1.2.tar.gz&lt;/li&gt;
		&lt;li&gt;tar zxvf autobench-2.1.2.tar.gz&lt;/li&gt;
		&lt;li&gt;cd autobench-2.1.2&lt;/li&gt;
		&lt;li&gt;./configure&lt;/li&gt;
		&lt;li&gt;make&lt;/li&gt;
		&lt;li&gt;checkinstall&lt;/li&gt;
		&lt;li&gt;mv autobench-2.1.2-i386-1.tgz /mnt/hda1/&lt;/li&gt;
	&lt;/ol&gt;


	&lt;p&gt;開始測試之前需要網站，這裡用本機的 Tomcat 來測。&lt;/p&gt;


	&lt;h3&gt;start tomcat&lt;/h3&gt;


	&lt;ol&gt;
	&lt;li&gt;uselivemod jre-1_5_0_08-linux.mo&lt;/li&gt;
		&lt;li&gt;uselivemod apache-tomcat-5.5.15.mo&lt;/li&gt;
		&lt;li&gt;/usr/local/tomcat/bin/startup.sh&lt;/li&gt;
		&lt;li&gt;netstat -at&lt;/li&gt;
	&lt;/ol&gt;


	&lt;h3&gt;httperf first run&lt;/h3&gt;


	&lt;p&gt;第一次跑用比較少的人數，只用 10 個。&lt;/p&gt;


	&lt;p&gt;httperf&amp;#8212;server=192.168.213.131&amp;#8212;port=8080&amp;#8212;rate=10&amp;#8212;num-conns=500&lt;/p&gt;


&lt;pre&gt;
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, &amp;lt;=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
&lt;/pre&gt;

	&lt;p&gt;換個動態 &lt;span class="caps"&gt;JSP&lt;/span&gt; 試看看，加上&amp;#8212;uri=/jsp-examples/jsp2/el/basic-arithmetic.jsp 跑起來，沒太大差異，都還沒到瓶頸。&lt;/p&gt;


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


	&lt;h3&gt;autobench first test&lt;/h3&gt;


	&lt;p&gt;轉用 autobench 來跑多次的結果方便找出掛掉的地方。&lt;/p&gt;


&lt;pre&gt;
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 
&lt;/pre&gt;

	&lt;p&gt;結果如下，大致還是可以看出 req_rate 都可以跟上。&lt;/p&gt;


&lt;pre&gt;
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
&lt;/pre&gt;

	&lt;p&gt;文字檔很難看出正確的趨勢，還是轉圖出來看比較方便找出關鍵。&lt;/p&gt;


	&lt;h3&gt;download gnuplot&lt;/h3&gt;


	&lt;p&gt;輸出圖案來判讀簡單了解，不過需要先下載 &lt;a href="http://www.slax.org/modules.php?category=graphics&amp;#38;id=899&amp;#38;name=gnuplot"&gt;gnuplot mo&lt;/a&gt;   來裝。&lt;/p&gt;


	&lt;ol&gt;
	&lt;li&gt;cd /mnt/hda1&lt;/li&gt;
		&lt;li&gt;wget gnuplot_4_0.mo&lt;/li&gt;
		&lt;li&gt;uselivemod gnuplot_4_0.mo&lt;/li&gt;
	&lt;/ol&gt;


	&lt;p&gt;裝好就可以用 bench2graph 跑看看。&lt;/p&gt;


	&lt;h3&gt; bench2png&lt;/h3&gt;


	&lt;p&gt;autobench 附的 bench2graph 會輸出 postscript 格式，這裡換成 &lt;span class="caps"&gt;PNG&lt;/span&gt; 格式。改成 echo set terminal png small color 的命令。&lt;/p&gt;


	&lt;ol&gt;
	&lt;li&gt;cd /usr/local/bin&lt;/li&gt;
		&lt;li&gt;cp bench2graph bench2png&lt;/li&gt;
		&lt;li&gt;vi bench2png&lt;/li&gt;
		&lt;li&gt;cd to autobench results dir&lt;/li&gt;
		&lt;li&gt;bench2png results.tsv result.png&lt;/li&gt;
	&lt;/ol&gt;


	&lt;p&gt;&lt;a href="/files/autobench_result_1.png" target="_blank"&gt;&lt;img src="/files/autobench_result_1.png" width="320" height="240"&gt;&lt;/a&gt;&lt;/p&gt;


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


&lt;pre&gt;
# 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
&lt;/pre&gt;

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


	&lt;p&gt;&lt;a href="/files/autobench_result_2.png" target="_blank"&gt;&lt;img src="/files/autobench_result_2.png" width="320" height="240"&gt;&lt;/a&gt;&lt;/p&gt;


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


	&lt;h3&gt; dir2mo autobench mo&lt;/h3&gt;


	&lt;p&gt;為求以後測試方便，將 httperf 與 autobench 包成一個 mo，同時加上改的 bench2png。&lt;/p&gt;


	&lt;ol&gt;
	&lt;li&gt;cd /mnt/hda1/work&lt;/li&gt;
		&lt;li&gt;mkdir autobench&lt;/li&gt;
		&lt;li&gt;installpkg -root autobench ../autobench-2.1.2-i386-1.tgz&lt;/li&gt;
		&lt;li&gt;installpkg -root autobench ../httperf-0.8-i386-1.tgz&lt;/li&gt;
		&lt;li&gt;cp /usr/local/bin/bench2png autobench/usr/local/bin/&lt;/li&gt;
		&lt;li&gt;dir2mo autobench autobench-2.1.2.mo&lt;/li&gt;
		&lt;li&gt;reboot for test.&lt;/li&gt;
	&lt;/ol&gt;


	&lt;p&gt;包完後開機一次做完整測試。&lt;/p&gt;


	&lt;h3&gt;uselivemod autobench-2.1.2.mo&lt;/h3&gt;


	&lt;ol&gt;
	&lt;li&gt;cd /mnt/hda1/work&lt;/li&gt;
		&lt;li&gt;uselivemod jre-1_5_0_08-linux.mo&lt;/li&gt;
		&lt;li&gt;uselivemod apache-tomcat-5.5.15.mo&lt;/li&gt;
		&lt;li&gt;uselivemod gnuplot_4_0.mo&lt;/li&gt;
		&lt;li&gt;uselivemod autobench-2.1.2.mo&lt;/li&gt;
		&lt;li&gt;/usr/local/tomcat/bin/startup.sh&lt;/li&gt;
		&lt;li&gt;cd /tmp&lt;/li&gt;
		&lt;li&gt;autobench again&lt;/li&gt;
		&lt;li&gt;bench2png results.tsv results.png 4 5 6 7 8&lt;/li&gt;
	&lt;/ol&gt;


	&lt;p&gt;這裡可以用更細的方式試看看，改取每次加五個方式。&lt;/p&gt;


&lt;pre&gt;
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 
&lt;/pre&gt;

	&lt;p&gt;看起來 750需求 (75連線) 左右就開始不穩。奇怪的是後來又線性上揚，不清楚是不是 &lt;span class="caps"&gt;JVM&lt;/span&gt; 的 GC 運作導致 Tomcat 一口氣喘不過來，有機會再多做些測試。&lt;/p&gt;


	&lt;p&gt;&lt;a href="/files/autobench_result_3.png" target="_blank"&gt;&lt;img src="/files/autobench_result_3.png" width="320" height="240"&gt;&lt;/a&gt;&lt;/p&gt;


	&lt;h3&gt;download autobench-2.1.2.mo&lt;/h3&gt;


	&lt;p&gt;&lt;img src="/files/archive.png" alt="" /&gt; &lt;a href="/files/autobench-2.1.2.mo"&gt;autobench-2.1.2.mo&lt;/a&gt;&lt;/p&gt;


	&lt;h3&gt;links&lt;/h3&gt;


	&lt;p&gt;&lt;a href="http://www.xenoclast.org/doc/benchmark/HTTP-benchmarking-HOWTO/"&gt;The Linux &lt;span class="caps"&gt;HTTP&lt;/span&gt; Benchmarking &lt;span class="caps"&gt;HOWTO&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;


	&lt;p&gt;&lt;a href="http://www.hpl.hp.com/research/linux/httperf/wisp98/html/doc001.html"&gt;httperf&amp;#8212;-A Tool for Measuring Web Server Performance&lt;/a&gt;&lt;/p&gt;</description>
      <pubDate>Wed, 13 Sep 2006 00:59:00 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:2a195d3b-6b44-41fa-a29c-e9c3d7453af9</guid>
      <author>LIN</author>
      <link>http://blog.extremepattern.com/articles/2006/09/13/httperf-and-autobench-in-slax</link>
      <category>java</category>
      <category>linux</category>
    </item>
  </channel>
</rss>
