使用ab 進行併發壓力測試 使用ab 進行併發壓力測試

 

使用ab 進行併發壓力測試 - 參與商 - 博客園 https://www.cnblogs.com/shenshangzz/p/8340640.htmlhtml

 

使用ab 進行併發壓力測試

 

ab全稱爲:apache bench。nginx

是apache自帶的壓力測試工具。ab很是實用,它不只能夠對apache服務器進行網站訪問壓力測試,也能夠對或其它類型的服務器進行壓力測試。好比nginx、tomcat、IIS等。apache

 

安裝ab命令:ubuntu

ubuntu:centos

sudo apt-get install apache2-utils

centos:緩存

yum install apr-util

# 安裝依賴 yum-utils中的yumdownload 工具
# 若是沒有找到 yumdownload 命令能夠
yum install yum-utils

 

使用:tomcat

簡單使用說明
1. 最基本的關心兩個選項 -c -n
例: ab -n 1000 -c 100 http://www.baidu.com/

-n 1000 即: 共發送1000個請求
-c 100 即:每次併發100個服務器

 

測試結果:網絡

命令:ab -n 1000 -c 1000 http://www.test.net/switch/get併發

複製代碼
This is ApacheBench, Version 2.3 <$Revision: 1528965 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking www.test.net(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
Completed 1000 requests
Finished 1000 requests


Server Software:        nginx/1.10.2
Server Hostname:        www.test.net
Server Port:            80

Document Path:          /switch/get
Document Length:        85 bytes

Concurrency Level:      1000
Time taken for tests:   2.296 seconds
Complete requests:      1000
Failed requests:        170
   (Connect: 0, Receive: 0, Length: 170, Exceptions: 0)
Non-2xx responses:      170
Total transferred:      496990 bytes
HTML transferred:       103360 bytes
Requests per second:    435.62 [#/sec] (mean)
Time per request:       2295.555 [ms] (mean)
Time per request:       2.296 [ms] (mean, across all concurrent requests)
Transfer rate:          211.43 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:       15  132  47.7    145     201
Processing:    89  428 225.7    382    2121
Waiting:       85  358 223.0    293    2121
Total:        198  559 233.0    512    2286

Percentage of the requests served within a certain time (ms)
  50%    512
  66%    603
  75%    697
  80%    751
  90%    850
  95%    910
  98%    935
  99%   1243
 100%   2286 (longest request)
複製代碼

 

結果分析:

服務器信息:

  採用nginx服務器,域名是www.test.net,端口號80端口。

Server Software:        nginx/1.10.2
Server Hostname:        www.test.net
Server Port:            80

文檔信息:

  文檔路徑/switch/get,文檔長度85字節(http響應的正文長度)

Document Path:          /switch/get
Document Length:        85 bytes

重要指標:

  Concurrency Level: 1000  // 1000個併發請求

  Time taken for tests: 2.296 seconds  // 整個測試持續時間

  Complete requests: 1000  // 完成了1000個請求

  Failed requests: 170 (Connect: 0, Receive: 0, Length: 170, Exceptions: 0)  // 失敗的請求數170

  Non-2xx responses: 170  // 170個不是2開頭的響應碼,好比緩存的304

  Total transferred: 496990 bytes  // 整個場景中的網絡傳輸量

  HTML transferred: 103360 bytes  // 整個場景中的HTML內容傳輸量

  Requests per second: 435.62 [#/sec] (mean)

  // 吞吐率(你們最關心的指標之一)

  服務器併發處理能力的量化描述,單位是reqs/s,指的是在某個併發用戶數下單位時間內處理的請求數。某個併發用戶數下單位時間內能處理的最大請求數,稱之爲最大吞吐率。

  記住:吞吐率是基於併發用戶數的。這句話表明了兩個含義:

  a、吞吐率和併發用戶數相關

  b、不一樣的併發用戶數下,吞吐率通常是不一樣的

  計算公式:總請求數/處理完成這些請求數所花費的時間,即

  Request per second=Complete requests/Time taken for tests

  必需要說明的是,這個數值表示當前機器的總體性能,值越大越好。

  Time per request: 2295.555 [ms] (mean)

   // 用戶平均請求等待時間,你們最關心的指標之二

  計算公式:處理完成全部請求數所花費的時間/(總請求數/併發用戶數)

  Time per request: 2.296 [ms] (mean, across all concurrent requests)

  // 服務器平均請求處理時間,你們最關心的指標之三

  計算公式:處理完成全部請求數所花費的時間/總請求數

  Transfer rate: 211.43 [Kbytes/sec] received  // 平均每秒網絡上的流量,能夠幫助排除是否存在網絡流量過大致使響應時間延長的問題

複製代碼
Concurrency Level:      1000
Time taken for tests:   2.296 seconds
Complete requests:      1000
Failed requests:        170
   (Connect: 0, Receive: 0, Length: 170, Exceptions: 0)
Non-2xx responses:      170
Total transferred:      496990 bytes
HTML transferred:       103360 bytes
Requests per second:    435.62 [#/sec] (mean)
Time per request:       2295.555 [ms] (mean)
Time per request:       2.296 [ms] (mean, across all concurrent requests)
Transfer rate:          211.43 [Kbytes/sec] received
複製代碼

 網絡上消耗的時間的分解:

複製代碼
Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:       15  132  47.7    145     201
Processing:    89  428 225.7    382    2121
Waiting:       85  358 223.0    293    2121
Total:        198  559 233.0    512    2286
複製代碼

每一個請求處理時間的分佈狀況,50%的處理時間在512ms內,66%的處理時間在603ms內...,重要的是看90%的處理時間:

複製代碼
Percentage of the requests served within a certain time (ms)
  50%    512
  66%    603
  75%    697
  80%    751
  90%    850
  95%    910
  98%    935
  99%   1243
 100%   2286 (longest request)
複製代碼

 

 

Download - The Apache Portable Runtime Project http://apr.apache.org/download.cgi

相關文章
相關標籤/搜索