慕課網實戰·高併發探索(一):詳細講解 - 網站性能測試工具Apache Bench

特別感謝:慕課網jimin老師的《Java併發編程與高併發解決方案》課程,以下知識點多數來自老師的課程內容。
jimin老師課程地址:Java併發編程與高併發解決方案


1、Apache Bench 簡介

Apache Bench是Apache 服務器附帶的工具,專門用來執行網站服務器的運行效能,特別是針對Apache 網站服務器。原本用來檢測Apache網站能夠提供的效能,特別是能看出Apache能提供每秒能送出多少網頁。

2、Apache Bench下載

我們到網站的官網去下載Apache服務器
下載地址:Apache服務器下載地址
這裏寫圖片描述
下載成功後直接進行解壓,無需安裝即可使用(僅針對於ApacheBench而言)。
這裏寫圖片描述

3、簡單的Apache Bench使用方法

  • 我們打開命令行界面,從命令行界面進入Apache Bench的解壓路徑下,進入後訪問bin文件夾。
    這裏寫圖片描述

  • 進入後我們輸入基礎的測試命令對接口進行測試(例如http://localhost:8080/test

  • ab -n 1000 -c 50 http://localhost:8080/test
  • 這段命令的含義是對於上述接口進行1000次測試,在同一時間內允許50個併發請求,執行結果如下:
    這裏寫圖片描述

4、測試結果講解

(1)測試指令參數說明:
Usage: ab [options] [http://]hostname[:port]/path
我們上述的測試指令中,options爲測試指令參數,其全部指參數說明如下:

Options are:(英文水平太爛,湊活看吧)

參數編碼(-?) 參數名 參數說明 含義
-n requests Number of requests to perform 總請求數
-c concurrency Number of multiple requests to make at a time 併發數量
-t timelimit Seconds to max. to spend on benchmarkin ,This implies -n 50000 測試時長最大秒數
-s timeout Seconds to max. wait for each response, Default is 30 seconds 每次請求等待響應的最長時間,默認30秒
-b windowsize Size of TCP send/receive buffer, in bytes TCP發送\接收緩存大小(單位bytes)
-B address Address to bind to when making outgoing connections 發送連接時綁定的地址
-p postfile File containing data to POST. Remember also to set -T 以POST方法發送文件,必須同時使用-T參數
-u putfile File containing data to PUT. Remember also to set -T 以PUT方法發送文件,必須同時使用-T參數
-T content-type Content-type header to use for POST/PUT data, eg., ‘application/x-www-form-urlencoded’, Default is ‘text/plain’ 使用POST\PUT方式時的Content-Type頭,例如:’application/x-www-form-urlencoded’,默認:’text/plain’
-v verbosity How much troubleshooting info to print 設置顯示信息的詳細程度 – 4或更大值會顯示頭信息, 3或更大值可以顯示響應代碼(404, 200等), 2或更大值可以顯示警告和其他信息。 -V 顯示版本號並退出
-w Print out results in HTML tables 以HTML表的格式輸出結果。默認時,它是白色背景的兩列寬度的一張表
-i Use HEAD instead of GET 使用HEAD請求
-x attributes String to insert as table attributes 插入字符串作爲表格屬性
-y attributes String to insert as tr attributes 插入字符串作爲tr屬性
-z attributes String to insert as td or th attributes 插入字符串作爲th屬性
-C attribute Add cookie, eg. ‘Apache=1234’. (repeatable) 添加cookie,可重複
-H attribute Add Arbitrary header line, eg. ‘Accept-Encoding: gzip’, Inserted after all normal header lines. (repeatable) 添加任意的頭信息,可重複
-A attribute Add Basic WWW Authentication, the attributes ,are a colon separated username and password. 添加基礎的www認證、屬性,是一個以冒號分割的賬號與密碼
-P attribute Add Basic Proxy Authentication, the attributes ,are a colon separated username and password. 添加基本的代理身份驗證、屬性,是一個以冒號分隔的用戶名和密碼。
-X proxy:port Proxyserver and port number to use 使用的代理服務和對應端口號
-V Print version number and exit 直接輸出版本號退出
-k Use HTTP KeepAlive feature 使用Http KeepAlice特性
-d Do not show percentiles served table.
-S Do not show confidence estimators and warnings. 不顯示confidence estimators和警告
-q Do not show progress when doing more than 150 requests 當超過150個請求的時候不顯示進程
-l Accept variable document length (use this for dynamic pages) 接受可變文檔長度(用於動態頁面)
-g filename Output collected data to gnuplot format file. 以gnuplot格式文件輸出收集的數據。
-e filename Output CSV file with percentages served 以CSV文件的方式輸出命中的服務
-r Don’t exit on socket receive errors. 返回error時不要終端socket
-m method Method name 方法名
-h Display usage information (this message) 顯示使用信息

(2)返回結果的說明:

字段名 解釋
Document Path 測試頁面
Document Length 頁面大小
Concurrency Level 併發量
Time taken for tests 整個測試持續的時間
Complete requests 完成的請求數量
Failed requests 失敗的請求數量
Total transferred 所有請求的響應數據的長度總和,包括每個http響應數據的頭信息和正文數據的長度,這裏不包括http請求數據的長度。僅僅爲WEB服務器流向用戶PC的應用層數據總長度
HTML transferred 所有請求的響應數據中正文數據的總和,數量上 = Total transferred - 響應數據頭信息的長度
Requests per second 吞吐率,相當於LR中的每秒事務數,後面括號中的mean表示這是一個平均值
Time per request 用戶平均請求等待時間,相當於LR中的平均事務響應時間,後面括號中的mean表示這是一個平均值
Time per request 服務器平均請求等待時間,每個連接請求實際運行時間的平均值
Transfer rate (單位時間內從服務器獲取的數據長度)平均每秒網絡上的流量,可以幫助排除是否存在網絡流量過大導致響應時間延長的問題。計算公式:(Total transferred : Time taken for tests)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章