1. 程式人生 > 實用技巧 >效能測試 - 工具 - Apache Bench(ab)

效能測試 - 工具 - Apache Bench(ab)

ab命令列引數

-n :總共的請求執行數,預設是1;
-c: 併發數,預設是1;
-t:測試所進行的總時間,秒為單位,預設50000s
-p:POST時的資料檔案
-w: 以HTML表的格式輸出結果

執行時終端配置

系統在做高併發測試時,有時發現連線數上不去,可以檢查下系統的ulimit,
ulimit –n 設定可以開啟的檔案描述符的最大值
在這裡插入圖片描述

  • ulimit –a (顯示當前所有的 limit 資訊)
  • ulimit -n 100000

命令列執行示例

例:總共請求100 併發10

  • 無cookie
    ab -n 100 -c 10 http://xxx
  • 有cookie
    ab -n 100 -c 10 -H “Cookie: xxx” “http://xxx”

測試結果解析

erver Software: Apache #伺服器軟體
Server Hostname: xxx.com #域名
Server Port: 80 #請求埠號

Document Path: / #檔案路徑
Document Length: 40888 bytes #頁面位元組數

Concurrency Level: 10 #請求的併發數
Time taken for tests: 27.300 seconds #總訪問時間
Complete requests: 1000 #請求成功數量
Failed requests: 0 #請求失敗數量
Write errors: 0
Total transferred: 41054242 bytes #請求總資料大小(包括header頭資訊)

HTML transferred: 40888000 bytes #html頁面實際總位元組數
Requests per second: 36.63 [#/sec] (mean) #每秒多少請求,這個是非常重要的引數數值,伺服器的吞吐量
Time per request: 272.998 [ms] (mean) #使用者平均請求等待時間
Time per request: 27.300 [ms] (mean, across all concurrent requests) # 伺服器平均處理時間,也就是伺服器吞吐量的倒數
Transfer rate: 1468.58 [Kbytes/sec] received #每秒獲取的資料長度
在這裡插入圖片描述