1.yum install -y httpd-tools
ab命令被集成到了httpd服務器中,所以想要使用ab命令需要先安裝httpd服務
ab -c 並發請求HTTP報文數量 -n 總共發送少個請求報文 http://www.oldboy.com/index,html
ab命令的使用方法和常用選項 ab [選項] [http[s]://]hostname[:port]/path 常用選項: -n requests Number of requests to perform
在測試會話中所執行的請求總個數,默認一個
-c concurrency Number of multiple requests to make at a time
一次產生的請求個數,默認一個
注意: 用Linux 做測試要做做好域名解析
vim /etc/hosts
10.0.0.7
2. 實例
[root@web01 conf.d]# ab -c 200 -n 200 http://www.oldboy.com/index.html 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 www.oldboy.com (be patient) Completed 100 requests Completed 200 requests Finished 200 requests Server Software: nginx/1.14.1 ---被測試的httpd服務器版本 Server Hostname: www.oldboy.com ---服務器主機名 Server Port: 80 ---服務器端口 Document Path: /index.html ---測試的文檔頁面 Document Length: 195 bytes ---測試的文檔大小 Concurrency Level: 200 ---並發數 Time taken for tests: 2.746 seconds ---整個測試時間 Complete requests: 200 ---完成請求個數 Failed requests: 118 ---失敗請求格式 (Connect: 0, Receive: 0, Length: 118, Exceptions: 0) Write errors: 0 Non-2xx responses: 200 Total transferred: 104236 bytes ---整個測試過程中總傳輸字節數 HTML transferred: 39118 bytes ---整個測試過程中HTML傳輸字節數 Requests per second: 72.82 [#/sec] (mean) ---每秒處理請求數,mean 表示這是一個平均值 Time per request: 2746.492 [ms] (mean) ---平均請求時間,mean表示這是一個平均值 Time per request: 13.732 [ms] (mean, across all concurrent requests) ---每個請求實際運行時間的平均值,mean表示這是一個平均值 Transfer rate: 37.06 [Kbytes/sec] received ---傳輸速率 Connection Times (ms) min mean[+/-sd] median max Connect: 254 266 7.0 266 277 Processing: 256 453 217.6 400 1816 Waiting: 256 453 217.6 400 1816 Total: 511 718 217.0 668 2074 Percentage of the requests served within a certain time (ms) 50% 668 66% 689 75% 712 80% 968 90% 992 95% 1112 98% 1250 99% 1358 100% 2074 (longest request)
3. 注意
測試上限一般是由打開文件的數量決定的,這個數值可以通過ulimit -a或ulimit -n命令查看,默認大小為1024。解決辦法就是ulimit -n [數值],來提高打開文件的數量上限,測試和被測試的都要提升。
