Nginx壓力測試工具之WebBench
在運維工作中,壓力測試是一項非常重要的工作。比如在一個網站上線之前,能承受多大訪問量、在大訪問量情況下效能怎樣,這些資料指標好壞將會直接影響使用者體驗。
但是,在壓力測試中存在一個共性,那就是壓力測試的結果與實際負載結果不會完全相同,就算壓力測試工作做的再好,也不能保證100%和線上效能指標相同。面對這些問題,我們只能儘量去想方設法去模擬。所以,壓力測試非常有必要,有了這些資料,我們就能對自己做維護的平臺做到心中有數。
目前較為常見的網站壓力測試工具有webbench、ab(apache bench)、tcpcopy、loadrunner。
webbench由Lionbridge公司開發,主要測試每秒鐘請求數和每秒鐘資料傳輸量,同時支援靜態、動態、SSL,部署簡單,靜動態均可測試。適用於小型網站壓力測試(單例最多可模擬3萬併發) 。
ab(apache bench)Apache自帶的壓力測試工具,主要功能用於測試網站每秒鐘處理請求個數,多見用於靜態壓力測試,功能較弱,非專業壓力測試工具。
tcpcopy基於底層應用請求複製,可轉發各種線上請求到測試伺服器,具有分散式壓力測試功能,所測試資料與實際生產資料較為接近後起之秀,主要用於中大型壓力測試,所有基於tcp的packets均可測試。
loadrunner壓力測試界的泰斗,可以建立虛擬使用者,可以模擬使用者真實訪問流程從而錄製成指令碼,其測試結果也最為逼真模擬最為逼真,並可進行獨立的單元測試,但是部署配置較為複雜,需要專業人員才可以。
下面,筆者就以webbench為例,來講解一下網站在上線之前壓力測試是如何做的。
安裝webbench
<span class="sh_preproc" style="color: rgb(160, 32, 240);">#wget</span> http<span class="sh_symbol">:</span><span class="sh_comment" style="color: rgb(255, 0, 0);">//home.tiscali.cz/~cz210552/distfiles/webbench-1.5.tar.gz</span> <span class="sh_preproc" style="color: rgb(160, 32, 240);">#tar</span> <span class="sh_usertype">zxvf</span><span class="sh_normal"> </span>webbench<span class="sh_number" style="color: rgb(255, 0, 255);">-1.5</span><span class="sh_symbol">.</span>tar<span class="sh_symbol">.</span>gz <span class="sh_preproc" style="color: rgb(160, 32, 240);">#cd</span> webbench<span class="sh_number" style="color: rgb(255, 0, 255);">-1.5</span> <span class="sh_preproc" style="color: rgb(160, 32, 240);">#make</span> <span class="sh_symbol">&&</span> make install
進行壓力測試,併發200時。
<span class="sh_preproc" style="color: rgb(160, 32, 240);"># webbench</span> <span class="sh_symbol">-</span>c <span class="sh_number" style="color: rgb(255, 0, 255);">200</span> <span class="sh_symbol">-</span>t <span class="sh_number" style="color: rgb(255, 0, 255);">60</span> http<span class="sh_symbol">:</span><span class="sh_comment" style="color: rgb(255, 0, 0);">//down.chinaz.com/index.php</span>
引數解釋:-c為併發數,-t為時間(秒)
Webbench <span class="sh_symbol">-</span> Simple Web Benchmark <span class="sh_number" style="color: rgb(255, 0, 255);">1.5</span> <span class="sh_function" style="font-weight: bold;">Copyright</span> <span class="sh_symbol">(</span>c<span class="sh_symbol">)</span> Radim Kolar <span class="sh_number" style="color: rgb(255, 0, 255);">1997-2004</span><span class="sh_symbol">,</span> GPL Open <span class="sh_usertype">Source</span><span class="sh_normal"> </span>Software<span class="sh_symbol">.</span> Benchmarking<span class="sh_symbol">:</span> <span class="sh_usertype">GET</span><span class="sh_normal"> </span>http<span class="sh_symbol">:</span><span class="sh_comment" style="color: rgb(255, 0, 0);">//down.chinaz.com/index.php</span> <span class="sh_number" style="color: rgb(255, 0, 255);">200</span> clients<span class="sh_symbol">,</span> running <span class="sh_number" style="color: rgb(255, 0, 255);">60</span> sec<span class="sh_symbol">.</span> Speed<span class="sh_symbol">=</span><span class="sh_number" style="color: rgb(255, 0, 255);">1454</span> pages<span class="sh_symbol">/</span>min<span class="sh_symbol">,</span> <span class="sh_number" style="color: rgb(255, 0, 255);">2153340</span> bytes<span class="sh_symbol">/</span>sec<span class="sh_symbol">.</span> Requests<span class="sh_symbol">:</span> <span class="sh_number" style="color: rgb(255, 0, 255);">1454</span> susceed<span class="sh_symbol">,</span> <span class="sh_number" style="color: rgb(255, 0, 255);">0</span> failed<span class="sh_symbol">.</span>
當併發200時,網站訪問速度正常
併發800時
<span class="sh_preproc" style="color: rgb(160, 32, 240);">#webbench</span> <span class="sh_symbol">-</span>c <span class="sh_number" style="color: rgb(255, 0, 255);">800</span> <span class="sh_symbol">-</span>t <span class="sh_number" style="color: rgb(255, 0, 255);">60</span> http<span class="sh_symbol">:</span><span class="sh_comment" style="color: rgb(255, 0, 0);">//down.chinaz.com/index.php</span> Webbench <span class="sh_symbol">-</span> Simple Web Benchmark <span class="sh_number" style="color: rgb(255, 0, 255);">1.5</span> <span class="sh_function" style="font-weight: bold;">Copyright</span> <span class="sh_symbol">(</span>c<span class="sh_symbol">)</span> Radim Kolar <span class="sh_number" style="color: rgb(255, 0, 255);">1997-2004</span><span class="sh_symbol">,</span> GPL Open <span class="sh_usertype">Source</span><span class="sh_normal"> </span>Software<span class="sh_symbol">.</span> Benchmarking<span class="sh_symbol">:</span> <span class="sh_usertype">GET</span><span class="sh_normal"> </span>http<span class="sh_symbol">:</span><span class="sh_comment" style="color: rgb(255, 0, 0);">//down.chinaz.com/index.php</span> <span class="sh_number" style="color: rgb(255, 0, 255);">800</span> clients<span class="sh_symbol">,</span> running <span class="sh_number" style="color: rgb(255, 0, 255);">60</span> sec<span class="sh_symbol">.</span> Speed<span class="sh_symbol">=</span><span class="sh_number" style="color: rgb(255, 0, 255);">1194</span> pages<span class="sh_symbol">/</span>min<span class="sh_symbol">,</span> <span class="sh_number" style="color: rgb(255, 0, 255);">2057881</span> bytes<span class="sh_symbol">/</span>sec<span class="sh_symbol">.</span> Requests<span class="sh_symbol">:</span> <span class="sh_number" style="color: rgb(255, 0, 255);">1185</span> susceed<span class="sh_symbol">,</span> <span class="sh_number" style="color: rgb(255, 0, 255);">9</span> failed<span class="sh_symbol">.</span>
當併發連線為800時,網站訪問速度稍慢
併發1600時
<span class="sh_preproc" style="color: rgb(160, 32, 240);">#webbench</span> <span class="sh_symbol">-</span>c <span class="sh_number" style="color: rgb(255, 0, 255);">1600</span> <span class="sh_symbol">-</span>t <span class="sh_number" style="color: rgb(255, 0, 255);">60</span> http<span class="sh_symbol">:</span><span class="sh_comment" style="color: rgb(255, 0, 0);">//down.chinaz.com/index.php</span>
Webbench <span class="sh_symbol">-</span> Simple Web Benchmark <span class="sh_number" style="color: rgb(255, 0, 255);">1.5</span>
<span class="sh_function" style="font-weight: bold;">Copyright</span> <span class="sh_symbol">(</span>c<span class="sh_symbol">)</span> Radim Kolar <span class="sh_number" style="color: rgb(255, 0, 255);">1997-2004</span><span class="sh_symbol">,</span> GPL Open <span class="sh_usertype">Source</span><span class="sh_normal"> </span>Software<span class="sh_symbol">.</span>
Benchmarking<span class="sh_symbol">:</span> <span class="sh_usertype">GET</span><span class="sh_normal"> </span>http<span class="sh_symbol">:</span><span class="sh_comment" style="color: rgb(255, 0, 0);">//down.chinaz.com/index.php</span>
<span class="sh_number" style="color: rgb(255, 0, 255);">1600</span> clients<span class="sh_symbol">,</span> running <span class="sh_number" style="color: rgb(255, 0, 255);">60</span> sec<span class="sh_symbol">.</span>
Speed<span class="sh_symbol">=</span><span class="sh_number" style="color: rgb(255, 0, 255);">1256</span> pages<span class="sh_symbol">/</span>min<span class="sh_symbol">,</span> <span class="sh_number" style="color: rgb(255, 0, 255);">1983506</span> bytes<span class="sh_symbol">/</span>sec<span class="sh_symbol">.</span>
Requests<span class="sh_symbol">:</span> <span class="sh_number" style="color: rgb(255, 0, 255);">1183</span> susceed<span class="sh_symbol">,</span> <span class="sh_number" style="color: rgb(255, 0, 255);">73</span> failed<span class="sh_symbol">.</span>
當併發連線為1600時,網站訪問速度便非常慢了
併發2000時
<span class="sh_preproc" style="color: rgb(160, 32, 240);">#webbench</span> <span class="sh_symbol">-</span>c <span class="sh_number" style="color: rgb(255, 0, 255);">2000</span> <span class="sh_symbol">-</span>t <span class="sh_number" style="color: rgb(255, 0, 255);">60</span> http<span class="sh_symbol">:</span><span class="sh_comment" style="color: rgb(255, 0, 0);">//down.chinaz.com/index.php</span> Webbench <span class="sh_symbol">-</span> Simple Web Benchmark <span class="sh_number" style="color: rgb(255, 0, 255);">1.5</span> <span class="sh_function" style="font-weight: bold;">Copyright</span> <span class="sh_symbol">(</span>c<span class="sh_symbol">)</span> Radim Kolar <span class="sh_number" style="color: rgb(255, 0, 255);">1997-2004</span><span class="sh_symbol">,</span> GPL Open <span class="sh_usertype">Source</span><span class="sh_normal"> </span>Software<span class="sh_symbol">.</span> Benchmarking<span class="sh_symbol">:</span> <span class="sh_usertype">GET</span><span class="sh_normal"> </span>http<span class="sh_symbol">:</span><span class="sh_comment" style="color: rgb(255, 0, 0);">//down.chinaz.com/index.php</span> <span class="sh_number" style="color: rgb(255, 0, 255);">2000</span> clients<span class="sh_symbol">,</span> running <span class="sh_number" style="color: rgb(255, 0, 255);">60</span> sec<span class="sh_symbol">.</span> Speed<span class="sh_symbol">=</span><span class="sh_number" style="color: rgb(255, 0, 255);">2154</span> pages<span class="sh_symbol">/</span>min<span class="sh_symbol">,</span> <span class="sh_number" style="color: rgb(255, 0, 255);">1968292</span> bytes<span class="sh_symbol">/</span>sec<span class="sh_symbol">.</span> Requests<span class="sh_symbol">:</span> <span class="sh_number" style="color: rgb(255, 0, 255);">2076</span> susceed<span class="sh_symbol">,</span> <span class="sh_number" style="color: rgb(255, 0, 255);">78</span> failed<span class="sh_symbol">.</span>
當併發2000時,網站便出現”502 Bad Gateway”,由此可見web伺服器已無法再處理使用者訪問請求
總結:
1、壓力測試工作應該放到產品上線之前,而不是上線以後
2、測試時儘量跨公網進行,而不是內網
3、測試時併發應當由小逐漸加大,比如併發100時觀察一下網站負載是多少、開啟是否流程,併發200時又是多少、網站開啟緩慢時併發是多少、網站打不開時併發又是多少
4、 應儘量進行單元測試,如B2C網站可以著重測試購物車、推廣頁面等,因為這些頁面佔整個網站訪問量比重較大
相關文章
- oracle壓力測試之orastress!OracleAST
- apache ab壓力測試工具-批次壓測指令碼Apache指令碼
- 10大主流壓力測試工具
- 軟體壓力測試知識分享,2022好用壓力測試工具有哪些?
- 超實用壓力測試工具-ab工具
- 讓測試事半功倍軟體壓力測試工具分享,壓力測試報告怎麼收費?測試報告
- oracle壓力測試之orabm(二)Oracle
- oracle壓力測試之orabm(三)Oracle
- oracle壓力測試之orabm(一)Oracle
- 雲伺服器nginx和webman壓力測試伺服器NginxWeb
- Linux下使用壓力測試工具stressLinux
- nodejs版的websocket壓力測試工具NodeJSWeb
- Linux系統壓力測試工具(命令列工具)Linux命令列
- 壓力測試
- 開源的負載測試/壓力測試工具 NBomber負載
- 軟體壓力測試流程和測試工具分享,讓你寫壓力測試報告再也不愁測試報告
- 10大主流壓力測試工具推薦
- sysbench 壓力測試
- MACOSXApacheab壓力測試MacApache
- ORACLE壓力測試Oracle
- laravel壓力測試Laravel
- NewSQL資料庫壓力測試工具系列——SysbenchSQL資料庫
- ActiveMQ壓力測試工具(emqtt_benchmark和jmeter)MQQTJMeter
- 壓力測試工具ab - Apache HTTP server benchmarking toolApacheHTTPServer
- 用雲壓力測試工具,如何完成一次測試任務
- Apache下壓力測試工具ab安裝與使用Apache
- 實現Python壓力測試工具|Python 主題月Python
- Nginx 高階篇(八)ab 壓力測試即 nginx 的效能統計模組Nginx
- (一)效能測試(壓力測試、負載測試)負載
- RestCloud測試平臺,支援壓力測試RESTCloud
- 開源API測試工具 Hitchhiker v0.6更新 – 改進壓力測試API
- 線上壓力測試工具-程式設計師線上工具網程式設計師
- 運維攻堅之jmeter壓力測試報錯運維JMeter
- Jmeter效能測試 —— 壓力模式JMeter模式
- Apache Bench Web 壓力測試ApacheWeb
- Jmeter 4.0壓力測試工具安裝及使用方法JMeter
- 網站效能壓力測試工具:Apache ab使用詳解網站Apache
- [資料庫]000 - ?Sysbench 資料庫壓力測試工具資料庫
- 軟體壓力測試怎麼做?出具壓力測試報告軟體測評中心測試報告