一、安裝
[root@node2 logs]# yum install httpd-tools 已加載插件:fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com 正在解決依賴關系 --> 正在檢查事務 ---> 軟件包 httpd-tools.x86_64.0.2.4.6-88.el7.centos 將被 安裝 --> 解決依賴關系完成 依賴關系解決 =============================================================================================== Package 架構 版本 源 大小 =============================================================================================== 正在安裝: httpd-tools x86_64 2.4.6-88.el7.centos base 90 k 事務概要 =============================================================================================== 安裝 1 軟件包 總下載量:90 k 安裝大小:169 k Is this ok [y/d/N]: y Downloading packages: httpd-tools-2.4.6-88.el7.centos.x86_64.rpm | 90 kB 00:00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction 正在安裝 : httpd-tools-2.4.6-88.el7.centos.x86_64 1/1 驗證中 : httpd-tools-2.4.6-88.el7.centos.x86_64 1/1 已安裝: httpd-tools.x86_64 0:2.4.6-88.el7.centos 完畢!
二、使用
參數說明:
-n :請求總次數
-c:並發數
-k:是否開啟長連接
-s:超時設置
例子:請求127.0.0.1,100次,並發10個
[root@node2 logs]# ab -n 100 -c 10 http://127.0.0.1/ This is ApacheBench, Version 2.3 <$Revision: 1430300 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking 127.0.0.1 (be patient).....done Server Software: nginx/1.14.2 Server Hostname: 127.0.0.1 Server Port: 80 Document Path: / Document Length: 612 bytes Concurrency Level: 10 Time taken for tests: 0.008 seconds Complete requests: 100 Failed requests: 0 Write errors: 0 Total transferred: 84500 bytes HTML transferred: 61200 bytes Requests per second: 12653.42 [#/sec] (mean) Time per request: 0.790 [ms] (mean) Time per request: 0.079 [ms] (mean, across all concurrent requests) Transfer rate: 10441.55 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.1 0 0 Processing: 0 1 0.1 1 1 Waiting: 0 1 0.1 1 1 Total: 0 1 0.1 1 1 Percentage of the requests served within a certain time (ms) 50% 1 66% 1 75% 1 80% 1 90% 1 95% 1 98% 1 99% 1 100% 1 (longest request)
以上輸出結果中
Concurrency Level: 10 並發數
Time taken for tests: 0.008 seconds 總耗時
Complete requests: 100 成功請求數
Failed requests: 0 失敗請求數
Requests per second: 12653.42 [#/sec] (mean) 即每秒的響應請求數,也即是最大吞吐能力(qps)總請求數/總耗時
Time per request: 0.790 [ms] (mean) 客戶端發出請求到收到響應,單個請求所耗費的時間
Time per request: 0.079 [ms] (mean, across all concurrent requests) 表示服務端處理單個請求所耗費的時間
那么 0.790-0.079=0.711ms ,表示單個請求在網絡傳輸中所耗費的時間,也就是說:客戶端發出請求到收到響應的耗時=網絡傳輸所耗費的時間+服務端處理請求所耗費的時間
Transfer rate: 10441.55 [Kbytes/sec] received :傳輸速率,當前為10M,可作為網絡環境測試的重要參考
