在linux中給你的應(yīng)用做壓力測試
一.webbench
- 在Ubuntu中安裝webbench —支持get,head等請求娜膘,但不支持post請求
wget http://blog.zyan.cc/soft/linux/webbench/webbench-1.5.tar.gztar zxvf webbench-1.5.tar.gzcd webbench-1.5make && make install
- 測試demo
webbench -t 5 -c 2 http://google.com/ >2個并發(fā)用戶共同請求5秒
- 測試結(jié)果分析
Benchmarking: GET http://google.com/ #GET方法請求谷歌
2 clients, running 5 sec. #2個用戶客税,運(yùn)行5秒
Speed=4296 pages/min, 38664 bytes/sec. #4296個頁面每秒肉津,38664 bytes每秒
Requests: 358 susceed, 0 failed. #358次請求成功卵蛉,0次失敗
二. ab
- 在Ubuntu中安裝ab —支持 post ,get ,head 等方法
sudo apt-get install apache2-utils
- 測試demo
ab -n 500 -c 2 http://www.google.com/ >2個并發(fā)用戶共同請求個數(shù)500個拘悦。
- 測試結(jié)果分析
Server Software: gws #服務(wù)器信息
Server Hostname: www.google.com #測試地址
Server Port: 80 #測試端口
Document Path: / #測試文檔路徑
Document Length: 390 bytes #測試文檔大小
Concurrency Level: 2 #并發(fā)數(shù)量
Time taken for tests: 6.752 seconds #測試消耗時間
Complete requests: 500 #完成的請求數(shù)
Failed requests: 0 #失敗的請求數(shù)
Non-2xx responses: 500 #HTTP響應(yīng)數(shù)據(jù)的頭信息中含有2XX以外的狀態(tài)碼的請求數(shù)
Total transferred: 566000 bytes #總傳輸數(shù)據(jù)大小
HTML transferred: 195000 bytes #總傳輸html數(shù)據(jù)大小
Requests per second: 74.05 [#/sec] (mean) #吞吐量锋爪,每秒處理平均請求數(shù)
Time per request: 27.007 [ms] (mean) #每個請求平均等待時間
Time per request: 13.504 [ms] (mean, across all concurrent requests) #服務(wù)器每個請求平均處理時間
Transfer rate: 81.86 [Kbytes/sec] received #平均每秒流量數(shù)
Connection Times (ms) #下面為時間花費(fèi)的分布(連接婆翔、處理水泉、等待善涨、總數(shù))
min mean[+/-sd] median max
Connect: 1 1 0.2 1 2
Processing: 22 26 7.6 25 150
Waiting: 22 26 7.6 25 150
Total: 23 27 7.6 26 151
//下面為每個請求花費(fèi)時間的分布
Percentage of the requests served within a certain time (ms)
50% 26 #50%在26毫秒之內(nèi)
66% 27 #66%在27毫秒之內(nèi)
75% 27
80% 27
90% 28 #主要看這個參數(shù)窒盐,90%在28毫秒之內(nèi)
95% 29
98% 36
99% 52
100% 151 (longest request)
如想在請求header加入數(shù)據(jù),如下:
ab -H "Cookie: key=value;key2=value2" ...
4.利用ab 進(jìn)行post請求
ab -c 1 -n 100 -T 'application/json' -p data.json http://www.google.com/
測試結(jié)果就不貼上來了钢拧,多了一個明顯的結(jié)果:
Total body sent: 15900 #body總的發(fā)送量