Apache -- ab 並發測試

來源:互聯網
上載者:User

標籤:

安裝了 apache 後, 在 bin 目錄下會有個叫 ab 的工具。它可以類比並發的 http 請求。我們可以用它來進行簡單的壓力測試。
進入 apache 的 bin 目錄,運行 ./ab -V 可以查看相關資訊: This is ApacheBench, Version 2.0.40-dev <$Revision: 1.146 $> apache-2.0 Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Copyright 2006 The Apache Software Foundation, http://www.apache.org/
進行某個地址的測試: [root @localhost ~]# ab -n1000 -c10 http://statis.abc.cn/ This is ApacheBench, Version 2.0.40-dev <$Revision: 1.146 $> apache-2.0 Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Copyright 2006 The Apache Software Foundation, http://www.apache.org/
Benchmarking statis.abc.cn (be patient) Completed 100 requests Completed 200 requests Completed 300 requests Completed 400 requests Completed 500 requests Completed 600 requests Completed 700 requests Completed 800 requests Completed 900 requests Finished 1000 requests

Server Software:     nginx/1.0.10 Server Hostname:     statis.abc.cn Server Port:       80
Document Path:      / Document Length:     4881 bytes
Concurrency Level:    10 Time taken for tests:  5.341769 seconds Complete requests:    1000 Failed requests:     0 Write errors:      0 Total transferred:    5253000 bytes HTML transferred:    4881000 bytes Requests per second:   187.20 [#/sec] (mean) Time per request:    53.418 [ms] (mean) Time per request:    5.342 [ms] (mean, across all concurrent requests) Transfer rate:      960.17 [Kbytes/sec] received
Connection Times (ms)        min  mean[+/-sd] median  max Connect:     0  19  11.6   18    40 Processing:   14  33  12.0   33    57 Waiting:    10  29  11.9   29    53 Total:     24  52  9.5   51    91
Percentage of the requests served within a certain time (ms)  50%   51  66%   55  75%   56  80%   59  90%   65  95%   73  98%   78  99%   82  100%   91 (longest request)
-------------------------------------- 上面資訊的解釋:
-n1000 總請求數為 1000
-c10 並發使用者數為 10 http://app.abc.cn/ 請求目標URL Server Software 被測試的地址用的WEB伺服器名稱。這裡是 nginx 1.0.10.它來自 HTTP 回應標頭。 Server Hostname 請求的URL的主機部分名稱,也來自 HTTP 回應標頭。 Server Port 被測試的WEB伺服器軟體監聽連接埠。 DocumentPath 請求的URL中的根絕對路徑,也是來自HTTP要求標頭。 DocumentLength 響應資料本文長度 Concurrency Level 並發使用者數,這裡是我們設定的參數。 Time taken for tests 所有這些請求處理完成所用的時間。 Complete requests 總請求數,這裡是我們設定的參數 Failed requests 失敗的請求數,失敗指的是請求在串連伺服器,發送資料,接收資料等環境發生異常,以及無響應後逾時的情況。對於逾時的時間,可以在 ab -t 參數設定. Total transferred 所有請求的響應資料長度總和。包括每個HTTP響應資料的頭資訊和本文資料長度。注意,它不包括請求資料的長度。 HTML transferred 表示所有請求的響應資料中本文資料的總和,也就是 Total transferred 中送去回應標頭的資料總和。 Requests per second 吞吐率: Complete requests / Time Time per request 使用者平均請求等待時間:Time taken for tests / (Complete requests / Concurrency Level) Time per request 伺服器平均請求處理時間:Time taken for tests /Complete requests.這正是吞吐率的倒數 Transfer rate 這些請求在單位時間內從伺服器擷取的資料長度:Total transferred  / Time taken for tests 這個統計可以很好說明伺服器在處理能力達到極限時,其出口頻寬的需求量。 Percentage of the requests served within a certain time (ms) 每個請求處理時間的分布情況。上面的結果顯示 80% 的請求回應時間不超過 59ms;(這是非常長的時間了,可能頁面裡有些複雜的邏輯)
******************************************************* 將並發使用者數從 10 變成 100,其它條件不變,看結果
[root @localhost ~]# ab -n1000 -c100 http://statis.abc.cn/
Server Software:     nginx/1.0.10 Server Hostname:     statis.easymobi.cn Server Port:       80
Document Path:      / Document Length:     4881 bytes
Concurrency Level:    100 Time taken for tests:  4.746772 seconds Complete requests:    1000 Failed requests:     0 Write errors:      0 Total transferred:    5265312 bytes HTML transferred:    4891824 bytes Requests per second:   210.67 [#/sec] (mean) Time per request:    474.677 [ms] (mean) Time per request:    4.747 [ms] (mean, across all concurrent requests) Transfer rate:      1083.05 [Kbytes/sec] received
Connection Times (ms)        min  mean[+/-sd] median  max Connect:     1  136 343.4   111   3130 Processing:   22  241 281.6   128   2382 Waiting:    18  181 166.8   125   1176 Total:     41  377 422.1   240   3247
Percentage of the requests served within a certain time (ms)  50%   240  66%   248  75%   255  80%   365  90%   766  95%  1064  98%  1483  99%  3232  100%  3247 (longest request)
從結果中看出,吞吐率從 187.20 增長到 210.67.伺服器平均請求處理時間從原來的 5.342ms 降到 4.747ms.而平均等待時間從 53.418 增加到 474.677.
可見,隨著並發使用者的變化,吞吐率,等待時間,請求處理時間都發生了相應的變化。

Apache -- ab 並發測試

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.