介紹
Webbench是一個在Linux下使用的網站壓測工具。它使用fork()模擬多個客戶端
同時訪問我們設定的URL,測試網站在壓力下工作的性能,
最多可以模擬3萬個並發連接去測試網站的負載能力。
安裝准備
首先我肯定需要在本地安裝webbench,步驟如下:
下載:[root@web02 tools]# wget http://www.ha97.com/code/webbench-1.5.tar.gz
解壓:[root@web02 tools]# tar xf webbench-1.5.tar.gz
安裝:
[root@web02 webbench-1.5]# make
cc -Wall -ggdb -W -O -c -o webbench.o webbench.c
webbench.c: In function ‘alarm_handler’:
webbench.c:77: warning: unused parameter ‘signal’
cc -Wall -ggdb -W -O -o webbench webbench.o
ctags *.c
/bin/sh: ctags: command not found
make: [tags] Error 127 (ignored)
[root@web02 webbench-1.5]# echo $?
0
[root@web02 webbench-1.5]# make install
install -s webbench /usr/local/bin
install -m 644 webbench.1 /usr/local/man/man1
install: cannot create regular file `/usr/local/man/man1′: No such file or directory
make: *** [install] Error 1
出現報錯,原因是沒找到/usr/local/man/man1目錄
現在創建:[root@web02 webbench-1.5]# mkdir -p /usr/local/man/man1
再次安裝:[root@web02 webbench-1.5]# make
ctags *.c
/bin/sh: ctags: command not found
make: [tags] Error 127 (ignored)
[root@web02 webbench-1.5]# echo $?
0
[root@web02 webbench-1.5]# make install
install -s webbench /usr/local/bin
install -m 644 webbench.1 /usr/local/man/man1
install -d /usr/local/share/doc/webbench
install -m 644 debian/copyright /usr/local/share/doc/webbench
install -m 644 debian/changelog /usr/local/share/doc/webbench
[root@web02 webbench-1.5]# echo $?
0
完成。
查看webbench使用幫助:
[root@web02 ~]# webbench –help
webbench [option]… URL
-f|–force Don’t wait for reply from server.
-r|–reload Send reload request – Pragma: no-cache.
-t|–time <sec> Run benchmark for <sec> seconds. Default 30.
-p|–proxy <server:port> Use proxy server for request.
-c|–clients <n> Run <n> HTTP clients at once. Default one.
-9|–http09 Use HTTP/0.9 style requests.
-1|–http10 Use HTTP/1.0 protocol.
-2|–http11 Use HTTP/1.1 protocol.
–get Use GET request method.
–head Use HEAD request method.
–options Use OPTIONS request method.
–trace Use TRACE request method.
-?|-h|–help This information.
-V|–version Display program version.
在本地服務器進測試:
[root@web02 ~]# webbench -c 1000 -t 10 http://blog.syk.com/test_info.php
Webbench – Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.
Benchmarking: GET http://blog.syk.com/test_info.php
1000 clients, running 10 sec.
Speed=11964 pages/min, 10327965 bytes/sec.
Requests: 1994 susceed, 0 failed
說明:一般我們只用到-c和-t兩個參數,其中-c:表示客戶端的訪問量,即並發數
-t表示運行測試的時間,如果不指定默認是30秒。
結果分析:
- Pages/min:指的輸出頁數/分
bytes/sec:是指字節/秒這兩個指標能反應網站的訪問速度。susceed和failed表示請求的成功數目和失敗數目,失敗的原因雖然沒有日志但是應該能猜出是get請求得不到200的響應。
在測試的過程中,再通過瀏覽器訪問被測試的網址能感覺到明顯的卡頓。
上面的測試使用了相同的參數(1000的並發數目,30秒),但是不能根據測試結果比較網站的性能。因為還有其它因素,比如測試的當前網頁有沒有涉及到數據庫的訪問等等。
下面是CSDN博客首頁測試:
[root@web02 ~]# webbench -c 1000 http://blog.csdn.net/
Webbench – Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.
Benchmarking: GET http://blog.csdn.net/
1000 clients, running 30 sec.
Speed=5224 pages/min, 20356 bytes/sec.
Requests: 2612 susceed, 0 failed.
淘寶網測試結果:
[root@web02 ~]# webbench -c 1000 http://www.taobao.com/
Webbench – Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.
Benchmarking: GET http://www.taobao.com/
1000 clients, running 30 sec.
Speed=4970 pages/min, 35821 bytes/sec.
Requests: 2485 susceed, 0 failed.