伺服器效能指標:Apache壓力測試工具ab
阿新 • • 發佈:2019-02-10
1. 概述
專案上線前,需要先知道web服務的效能指標,也就是伺服器的併發處理能力。 伺服器的吞吐率, 即qps, query per seconds. 需要通過壓力測試來知道效能。 常用壓測的工具 ab, ApacheBench2. ab安裝
ab為Apache附帶壓測工具。 安裝Apache後在 apache/bin 目錄下3. ab使用
先檢查ab工具是否正常,檢視其版本號cd apache/bin
./ab -V
輸出值
開始壓測This is ApacheBench, Version 2.3 <$Revision: 1554214 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/
./ab -n1000 -c10 http://localhost:8999/index.html
可以看到下面的結果
Server Software: Apache/2.4.9 Server Hostname: localhost Server Port: 8999 Document Path: /index.html Document Length: 45 bytes Concurrency Level: 10 Time taken for tests: 0.223 seconds Complete requests: 1000 Failed requests: 0 Total transferred: 299000 bytes HTML transferred: 45000 bytes Requests per second: 4477.76 [#/sec] (mean) Time per request: 2.233 [ms] (mean) Time per request: 0.223 [ms] (mean, across all concurrent requests) Transfer rate: 1307.47 [Kbytes/sec] received
4. ab常用引數
-h 顯示幫助資訊 -V 檢視版本號 -c 併發使用者數 -n 總請求數 -C 請求cookie,用法 "cookie_name=value", 可重複 -d 不顯示"percentage served within XX [ms] table". -H 增加額外的請求頭, -i 用HEAD請求代替GET -k 啟用Http keepalive功能, -v 顯示詳細資訊 "-v4" 4或更大值會顯示頭資訊,"-v3" 3或更大值可以顯示響應程式碼(404,200等),2或更大值可以顯示警告和其他資訊。 -w 以html格式輸出結果 -t 超時時間,所有請求的最大執行時間,預設沒有限制。5. ab測試結果欄位意思
Server Software: 伺服器名稱
Server Hostname: url主機名稱
Server Port: 埠
Document Path: url中絕對路徑
Document Length: Http相應資料的正文長度
Concurrency Level: 併發使用者數,我們用-c設定的引數
Time taken for tests: 所有請求處理完花費的時間 秒 seconds
Complete requests: 總請求數,我們用-n設定的引數
Failed requests: 表示失敗的請求數,
指請求在連線伺服器,傳送資料,接收資料等環節發生的異常,以及無響應後超時,超時時間可以用-t 來設定
另外,如果響應頭的http狀態碼為2XX以外的值,這些不算在失敗的請求
Total transferred: 表示http響應頭和正文的總和 bytes
HTML transferred: 相應正文的總和 bytes
Requests per second: 這是最重要的資料,表示每秒處理請求數 requests per seconds 4634.07 [#/sec] (mean)
Time per request: 使用者平均等待時間2.158 [ms] (mean)
Time per request: 伺服器平均處理時間 0.216 [ms] (mean, across all concurrent requests)
Transfer rate: 每秒從伺服器獲取的資料長度 1353.11 [Kbytes/sec] received
Percentage of the requests served within a certain time (ms) 每個請求處理時間的分佈