1. 程式人生 > >apache-ab併發負載壓力測試 不錯

apache-ab併發負載壓力測試 不錯

  • ab -n 3000 -c 3000 http://www.test.com/
    • c 100 即:每次併發3000 個
    • n 10000 即: 共傳送3000 個請求
  • ab -t 60 -c 100 http://192.168.0.10/
    • 在60秒內發請求,一次100個請求。

帶引數的的請求

  • ab -t 60 -c 100 -T "application/x-www-form-urlencoded" p p.txt http://192.168.0.10/hello.html

    • p.txt 是和ab.exe在一個目錄 p.txt 中可以寫引數,如 p=wdp&fq=78 要注意編碼問題
  • 引數中的三種形式

    • application/x-www-form-urlencoded (預設值)
      • 就是設定表單傳輸的編碼,典型的post請求
    • multipart/form-data.
      • 用來指定傳輸資料的特殊型別的,主要就是我們上傳的非文字的內容,比如圖片,mp3,檔案等等
    • text/plain . 是純文字傳輸的意思

結果分析

 
Paste_Image.png   Paste_Image.png
  • 結果引數解釋:
This is ApacheBench, Version 2.3
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 192.168.80.157 (be patient) Completed 400 requests Completed 800 requests Completed 1200 requests Completed 1600 requests Completed 2000 requests Completed 2400 requests Completed 2800 requests Completed 3200 requests Completed 3600 requests Completed 4000 requests Finished 4000 requests Server Software: Apache/2.2.15 Server Hostname: 192.168.80.157 Server Port: 80 Document Path: /phpinfo.php #測試的頁面 Document Length: 50797 bytes #頁面大小 Concurrency Level: 1000 #測試的併發數 Time taken for tests: 11.846 seconds #整個測試持續的時間 Complete requests: 4000 #完成的請求數量 Failed requests: 0 #失敗的請求數量 Write errors: 0 Total transferred: 204586997 bytes #整個過程中的網路傳輸量 HTML transferred: 203479961 bytes #整個過程中的HTML內容傳輸量 Requests per second: 337.67 [#/sec] (mean) #最重要的指標之一,相當於LR中的每秒事務數,後面括號中的mean表示這是一個平均值 Time per request: 2961.449 [ms] (mean) #最重要的指標之二,相當於LR中的平均事務響應時間,後面括號中的mean表示這是一個平均值 Time per request: 2.961 [ms] (mean, across all concurrent requests) #每個連線請求實際執行時間的平均值 Transfer rate: 16866.07 [Kbytes/sec] received #平均每秒網路上的流量,可以幫助排除是否存在網路流量過大導致響應時間延長的問題 Connection Times (ms) min mean[+/-sd] median max Connect: 0 483 1773.5 11 9052 Processing: 2 556 1459.1 255 11763 Waiting: 1 515 1459.8 220 11756 Total: 139 1039 2296.6 275 11843 #網路上消耗的時間的分解,各項資料的具體演算法還不是很清楚 Percentage of the requests served within a certain time (ms) 50% 275 66% 298 75% 328 80% 373 90% 3260 95% 9075 98% 9267 99% 11713 100% 11843 (longest request) #整個場景中所有請求的響應情況。在場景中每個請求都有一個響應時間,其中50%的使用者響應時間小於275毫秒,66%的使用者響應時間小於298毫秒,最大的響應時間小於11843毫秒。對於併發請求,cpu實際上並不是同時處理的,而是按照每個請求獲得的時間片逐個輪轉處理的,所以基本上第一個Time per request時間約等於第二個Time per request時間乘以併發請求數。 

ab使用的一些問題

  • ab命令在一般系統上面做測試時候,一般併發不能超過1024個,其實是因為因為系統限制每個程序開啟的最大檔案數為1024,可以用ulimit -a來檢視
  • -n 可以指定最大請求數,但是不能超過50000個
  • -v n 當n>=2 時,可以顯示傳送的http請求頭,和響應的http頭及內容,壓力測試時不要這麼做
  • 在做壓力測試的時候,一般情況下壓力測試客戶端接收到的資料量一定會遠大於傳送出去的資料量
  • 針對一般併發不能超過1024個問題解決方案


作者:望月成三人
連結:https://www.jianshu.com/p/166a4ea8aade
來源:簡書
簡書著作權歸作者所有,任何形式的轉載都請聯絡作者獲得授權並註明出處。