【Linux】ApacheBench(ab)壓力測試工具


AB的簡介

  ab是apachebench命令的縮寫。

  ab是apache自帶的壓力測試工具。ab非常實用,它不僅可以對apache服務器進行網站訪問壓力測試,也可以對或其它類型的服務器進行壓力測試。比如nginx、tomcat、IIS等

ab的原理

  ab的原理:ab命令會創建多個並發訪問線程,模擬多個訪問者同時對某一URL地址進行訪問。它的測試目標是基於URL的,因此,它既可以用來測試apache的負載壓力,也可以測試nginx、lighthttp、tomcat、IIS等其它Web服務器的壓力。

  ab命令對發出負載的計算機要求很低,它既不會占用很高CPU,也不會占用很多內存。但卻會給目標服務器造成巨大的負載,其原理類似CC攻擊。自己測試使用也需要注意,否則一次上太多的負載。可能造成目標服務器資源耗完,嚴重時甚至導致死機

ab的安裝

  安裝命令:yum -y install httpd-tools

  

  查看版本命令:ab -V

  

  查看參數說明:ab --help

ab的使用

  常用方式:ab -c 500 -n 5000 http://localhost/

  

[root@H__D /]# ab -c 500 -n 5000 http://localhost/
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 localhost (be patient)
Completed 500 requests
Completed 1000 requests
Completed 1500 requests
Completed 2000 requests
Completed 2500 requests
Completed 3000 requests
Completed 3500 requests
Completed 4000 requests
Completed 4500 requests
Completed 5000 requests
Finished 5000 requests


Server Software:        nginx/1.15.3        #測試服務器的名字
Server Hostname:        localhost            #請求的URL主機名
Server Port:            80                          #請求端口

Document Path:          /                        #請求路徑
Document Length:        613 bytes          #HTTP響應數據的正文長度

Concurrency Level:      500                    #並發用戶數,這是我們設置的參數之一
Time taken for tests:   0.407 seconds     #所有這些請求被處理完成所花費的總時間 單位秒
Complete requests:      5000                  #總請求數量,這是我們設置的參數之一
Failed requests:        0                           #表示失敗的請求數量
Write errors:           0                            
Total transferred:      4230000 bytes       #所有請求的響應數據長度總和。包括每個HTTP響應數據的頭信息和正文數據的長度
HTML transferred:       3065000 bytes     #所有請求的響應數據中正文數據的總和,也就是減去了Total transferred中HTTP響應數據中的頭信息的長度
Requests per second:    12284.44 [#/sec] (mean)    #吞吐量,計算公式:Complete requests/Time taken for tests  總請求數/處理完成這些請求數所花費的時間
Time per request:       40.702 [ms] (mean)             #用戶平均請求等待時間,計算公式:Time token for tests/(Complete requests/Concurrency Level)。處理完成所有請求數所花費的時間/(總請求數/並發用戶數)     
Time per request:       0.081 [ms] (mean, across all concurrent requests)    #服務器平均請求等待時間,計算公式:Time taken for tests/Complete requests,正好是吞吐率的倒數。也可以這么統計:Time per request/Concurrency Level
Transfer rate:          10149.06 [Kbytes/sec] received。  #表示這些請求在單位時間內從服務器獲取的數據長度,計算公式:Total trnasferred/ Time taken for tests,這個統計很好的說明服務器的處理能力達到極限時,其出口寬帶的需求量。

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    2   0.8      1       6
Processing:     3    5   7.9      5     399
Waiting:        0    4   7.9      4     399
Total:          4    7   8.0      7     404
WARNING: The median and mean for the initial connection time are not within a normal deviation
        These results are probably not that reliable.

Percentage of the requests served within a certain time (ms)
  50%      7               #50%用戶請求在7ms內返回
  66%      7               #60%用戶請求在7ms內返回
  75%      7
  80%      7
  90%      7
  95%      7
  98%     12              #98%用戶請求在12ms內返回
  99%     12
 100%    404 (longest request)                                                     

使用注意

  1、MAC中應該是自帶了Apache。

  2、在使用ab命令時,並發了過高會出現錯誤:Too many open files,由於系統打開文件數量限制了。

  

  查看系統打開文件數量,命令:ulimit -a
  

  修改打開文件數量,修改成1024,命令:ulimit -n 1024

  查看修改后情況,命令:ulimit -n

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM