httpmark.mo
Sep
有些事要先知道
部落格的文件發布時間不一致,有時寫的時候並沒有考慮到後來的發展,所以文件往往缺乏一貫與完整性,為避免看的人一頭霧水,於是在文件前稍微介紹一下這個練習的來龍去脈。
- 如何使用 vmplayer 玩 ISO 檔請參考 dsl in vmplayer
- slax 在 vmplayer 上玩請參考 Slax popcorn in vmplayer
- gcin 中文輸入請參考 gcin in slax popcorn
- jre/apr-tcnative/tomcat 請參考 Native Tomcat in Slax
- 網頁測試 autobench.mo 請參考 httperf and autobench
源起
之前包 autobench.mo 為求方便,只有加個輸出單張的 PNG 的 script 而已,這次想要修改一下輸出樣式,可以輸出一個簡易 HTML 報告, 這樣到底是要繼續改 bench2png 還是另外作 ? 這裡選擇另外作 shell script 來跑,因為 perl 不熟 :-)
要輸出 HTML 當然需要 HTTP 服務,內建要選小一點的,所以選 lighttpd 供測試與展示 HTML 使用。
lighttpd inside
注意編譯 lighttpd 期間需要 pcre 支援,安裝完並不需要這個 pcre。
- wget pcre; configure; make; checkinstall
- wget lighttpd; configure; make; checkinstall
試運轉後發現 lighttpd 需要使用 sendfile 支援,而這個部份似乎有點問題,必須考量將 www 等目錄掛在 tmpfs 上。
- cd /mnt/hda1/work
- mkdir httpmark
- installpkg -root httpmark ../httperf-0.8-i386-1.tgz
- installpkg -root httpmark ../autobench-2.1.2-i386-1.tgz
- installpkg -root httpmark ../lighttpd-1.4.11-i386-1.tgz
- cd httpmark
- mkdir -p usr/local/lighttpd/www/test
- mkdir -p usr/local/lighttpd/logs
- echo “httpmark work” > usr/local/lighttpd/www/index.html
- echo “httpmark test” > usr/local/lighttpd/www/test/index.html
這裡預設會輸出 4 個圖檔,與 4 個 tsv 檔。
<img src="hmark_1.png"/> <a href="hmark_1.tsv.txt">hmark_1.tsv</a> .....
同時放幾個 jpg 檔進去。test10k/test20k/test50k/test100k,同時把設定檔調一下。
- cp /mnt/hda1/lighttpd-1.4.11/doc/lighttpd.conf usr/local/lighttpd/
- cp /mnt/hda1/lighttpd-1.4.11/doc/rc.lighttpd usr/local/lighttpd/
- cd usr/local/lighttpd/
接下來改 lighttpd 啟動檔, vi my.lighttpd 如下,主要是一開始劃出 tmpfs 來掛的要求必須滿足。
#! /bin/sh
# Check lighttpd
LIGHTTPD_BIN=/usr/local/sbin/lighttpd
if [ ! -e $LIGHTTPD_BIN ]; then
echo "ERROR : $LIGHTTPD_BIN DO NOT exist."
exit 0
fi
#
# check tmpfs for lighttpd
#
LIGHTTPD_HOME=/usr/local/lighttpd
LIGHTTPD_FS=/usr/local/tmpfs/lighttpd
target=`df -h | grep "$LIGHTTPD_FS"`
if [ "$target" == "" ]; then
echo "Mount tmpfs in $LIGHTTPD_FS"
[ -e $LIGHTTPD_FS ] || mkdir -p $LIGHTTPD_FS
mount tmpfs $LIGHTTPD_FS -t tmpfs -o size=24m
mkdir -p $LIGHTTPD_FS/logs
cp -r $LIGHTTPD_HOME/www/ $LIGHTTPD_FS
fi
LIGHTTPD_HOME=/usr/local/lighttpd
LIGHTTPD_CONF_PATH=$LIGHTTPD_HOME/lighttpd.conf
case "$1" in
start)
echo "Starting lighttpd..."
# check if lighttpd.pid file exists [mylighttpd.sh creates it.]
if [ -e $LIGHTTPD_HOME/lighttpd.pid ] ; then
pid=`cat $LIGHTTPD_HOME/lighttpd.pid`
# check if process is still running
if [ -d "/proc/$pid" ]; then
echo "lighttpd already running as process $pid.Stop it first.."
exit 0
fi
fi
$LIGHTTPD_BIN -f $LIGHTTPD_CONF_PATH &
echo $! > $LIGHTTPD_HOME/lighttpd.pid
;;
stop)
echo "Shutting down lighttpd..."
if [ -e $LIGHTTPD_HOME/lighttpd.pid ] ; then
pid=`pgrep lighttpd`
kill $pid
rm $LIGHTTPD_HOME/lighttpd.pid
fi
;;
restart)
## Stop the service and regardless of whether it was
## running or not, start it again.
$0 stop
$0 start
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
;;
esac
然後修改設定檔,將路徑指到 tmpfs 去。
vi usr/local/lighttpd/lighttpd.conf
server.document-root = "/usr/local/tmpfs/lighttpd/www/" server.errorlog = "/usr/local/tmpfs/lighttpd/logs/lighttpd.error.log" accesslog.filename = "/usr/local/tmpfs/lighttpd/logs/access.log"
接下來重開機測試 lighttpd。
#dir2mo httpbench httpmark-0.1.mo #reboot- uselivemod httpmark-0.1.mo
- /usr/local/lighttpd/my.lighttpd start
- netstat -at
- check http://127.0.0.1/
gnuplot 的樣本檔
建立一個 gnuplot 的樣本檔,可以先跑看看,然後到時候用 sed 換字就好。
- cd /mnt/hda1/work/httpmark
- mkdir usr/local/httpmark
- cd usr/local/httpmark
- vi httpmark.plt
set terminal png small color set key outside below set key box set grid set output "results.png" set data style linespoints set title "results.title" set xlabel "X Axis : dem_req_rate" set y2tics set ytics nomirror set y2label "Y2 Axis : Mbps" plot "results.tsv" using 1:2 every ::1 ti "req rate" , \ "results.tsv" using 1:3 every ::1 ti "conn rate" , \ "results.tsv" using 1:7 every ::1 ti "std_req_rate", \ "results.tsv" using 1:8 every ::1 ti "resp_time(ms)", \ "results.tsv" using 1:10 every ::1 ti "error", \ "results.tsv" using 1:($9*8/1024) every ::1 ti "net_io(Y2)" axis x1y2
關於 gnuplot 可以參考。
http://t16web.lanl.gov/Kawano/gnuplot/plot1-e.html#5.2 http://www.gnuplot.info/faq/faq.html http://www.gentoo.org/doc/en/articles/l-awk1.xml?style=printable
httpmark.sh
- vi httpmark.sh
- chmod +x httpmark.sh
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
export PATH
echo "httpbench runing...."
echo "test : $1"
echo "low rate : $2"
echo "high rate : $3"
echo "num call : $4"
echo "num conn : $5"
echo "rate step : $6"
#
# check autobench
#
abcmd=/usr/local/bin/autobench
if [ ! -e $abcmd ]; then
echo "autobench is not install."
exit 0
fi
#
# autobench need conf file
#
exaconf=/usr/local/etc/autobench.conf
aconf=$HOME/.autobench.conf
[ ! -e "$aconf" ] && cp $exaconf $aconf
#
# gnuplot template
#
HTTPMARK_HOME=/usr/local/httpmark
plt=$HTTPMARK_HOME/httpmark.plt
HTDOC=/usr/local/tmpfs/lighttpd/www
#
# run autobench
#
uri="/test"
testfile="test10k.jpg"
echo "Run autobench with num_call $4"
tsvfile=hmark_$1.tsv
echo "tsv file : $tsvfile"
pngfile=hmark_$1.png
echo "png file : $pngfile"
title="hmark($testfile) n_call=$4,n_conn=$5"
echo "title : $title"
autobench --single_host --host1 127.0.0.1 \
--port1 80 --uri1 $uri/$testfile --quiet \
--low_rate $2 --high_rate $3 --rate_step $6 \
--num_call $4 --num_conn $5 --timeout 5 \
--file $tsvfile
# sed file
sed -e "s/results.tsv/$tsvfile/g" \
-e "s/results.png/$pngfile/g" \
-e "s/results.title/$title/g" $plt | gnuplot
mv $pngfile $HTDOC/
mv $tsvfile $HTDOC/$tsvfile.txt
echo "httpbench done."
exit 0
- /usr/local/httpmark/httpmark.sh
- dir2mo httpmark httpmark-0.1.mo
- reboot
final run
- uselivemod gnuplot.mo
- uselivemod httpmark-0.1.mo
- /usr/local/lighttpd/my.lighttpd start
- /usr/local/httpmark/httpmark.sh 1 50 150 1 600 10
跑完可以到 http://127.0.0.1 去看結果,測試需要不斷調整觀察,這個部份是最難的,一直到找出轉折點,換成 httpmark.sh 2 xx xx xx xx xx 繼續跑,可以放 4 個結果。