1. 程式人生 > >【壓測】壓力測試ab的用法【原創】.md

【壓測】壓力測試ab的用法【原創】.md

簡介

ab(Apache Bench)是Apache附帶的壓力測試軟體,容易使用,功能完全能夠滿足我們的要求,安裝apache時會自帶該壓力測試軟體

引數說明

ab自帶的引數說明:

[[email protected] images]# ab -h
Usage: ab [options] [http[s]://]hostname[:port]/path
Options are:
    -n requests Number of requests to perform
    -c concurrency Number of multiple requests to make
-t timelimit Seconds to max. wait for responses -b windowsize Size of TCP send/receive buffer, in bytes -p postfile File containing data to POST. Remember also to set -T -u putfile File containing data to PUT. Remember also to set -T -T content-type Content-type header for POSTing
, eg.
'application/x-www-form-urlencoded' Default is 'text/plain' -v verbosity How much troubleshooting info to print -w Print out results in HTML tables -i Use HEAD instead of GET -x attributes String to insert as table attributes -y attributes String
to insert as tr attributes
-z attributes String to insert as td or th attributes -C attribute Add cookie, eg. 'Apache=1234. (repeatable) -H attribute Add Arbitrary header line, eg. 'Accept-Encoding: gzip' Inserted after all normal header lines. (repeatable) -A attribute Add Basic WWW Authentication, the attributes are a colon separated username and password. -P attribute Add Basic Proxy Authentication, the attributes are a colon separated username and password. -X proxy:port Proxyserver and port number to use -V Print version number and exit -k Use HTTP KeepAlive feature -d Do not show percentiles served table. -S Do not show confidence estimators and warnings. -g filename Output collected data to gnuplot format file. -e filename Output CSV file with percentages served -r Don't exit on socket receive errors. -h Display usage information (this message) -Z ciphersuite Specify SSL/TLS cipher suite (See openssl ciphers) -f protocol Specify SSL/TLS protocol (SSL2, SSL3, TLS1, or ALL)

ab的引數比較多,常用的就幾個:

  • -n :在測試會話中執行的請求個數,即請求數,預設執行一個請求
  • -c :要建立的併發使用者數,即併發數,預設建立一個使用者數
  • -t :等待Web伺服器響應的最大時間(單位:秒),預設沒有時間限制
  • -k :使用Keep-Alive(持久連線)特性
  • -C :對請求附加一個Cookie,形式為 name=value

用法

下面使用ab進行一次壓力測試:

[[email protected] images]# ab -c5 -n100 -k xxx.com/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking cms.dev.paidui.com (be patient).....done

Server Software: Tengine
Server Hostname: cms.dev.paidui.com
Server Port: 80

Document Path: /
Document Length: 30692 bytes

Concurrency Level: 5
Time taken for tests: 20.663 seconds
Complete requests: 100
Failed requests: 10
   (Connect: 0, Receive: 0, Length: 10, Exceptions: 0)
Write errors: 0
Non-2xx responses: 10
Keep-Alive requests: 10
Total transferred: 2881762 bytes
HTML transferred: 2822279 bytes
Requests per second: 4.84 [#/sec] (mean)
Time per request: 1033.169 [ms] (mean)
Time per request: 206.634 [ms] (mean, across all concurrent requests)
Transfer rate: 136.19 [Kbytes/sec] received

Connection Times (ms)
              min mean[+/-sd] median max
Connect: 0 5 2.1 6 11
Processing: 9 984 1007.0 739 7508
Waiting: 9 330 230.7 257 1278
Total: 9 989 1007.2 744 7513

Percentage of the requests served within a certain time (ms)
  50% 744
  66% 919
  75% 1130
  80% 1222
  90% 1772
  95% 2422
  98% 4720
  99% 7513
 100% 7513 (longest request)

測試結果一目瞭然,吞吐率為4.84 reqs/s(吞吐率即單位時間內伺服器處理的請求數)

測試結果中關注以下內容:

  • Server Software: 被測試Web伺服器的軟體名稱
  • Server Hostname: 請求URL中的主機名稱
  • Server Port: 被測試Web伺服器的偵聽埠
  • Document Path: 請求的URL的絕對路徑
  • Document Length: HTTP響應資料的正文長度
  • Concurrency Level: 併發使用者數,設定的“-c”引數
  • Time taken for tests: 所有請求處理完成所花費的總時間
  • Complete requests: 總請求數,設定的“-n”引數
  • Failed requests: 失敗的請求數
  • Total transferred: 所有請求的響應資料長度總和
  • HTML transferred: 所有請求的響應資料中正文資料的總和,也就是減去Total transferred中HTTP響應資料中頭資訊的長度
  • Requests per second: Web伺服器的吞吐率,等於 Complete requests/Time taken for tests
  • Time per request: 使用者平均請求等待時間,等於 Time taken for tests/(Complete requests/Concurrency Level)
  • Transfer rate: 這些請求在單位時間內從伺服器取得的資料長度,等於 Total transferred/Time taken for tests

持久連線

持久連線(Keep-Alive)又稱長連線,指TCP連線中連續傳送多份資料而不斷開的連線,與之對應的稱為短連線,就是連線後傳送一次資料便斷開的連線。長連線對於密集型圖片或者網頁等小資料請求處理有明顯的加速作用。

在請求大量小檔案時,長連線能夠有效地減少重新建立連線的開銷。在啟動ab時加上-k引數可以使用Keep-Alive模式進行測試

比如:

先測試不使用長連線請求一個圖片:

[[email protected] images]# ab -c10 -n1000 cms.dev.paidui.com/images/3gphost.jpg
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking cms.dev.paidui.com (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: Tengine
Server Hostname: cms.dev.paidui.com
Server Port: 80

Document Path: /images/3gphost.jpg
Document Length: 169 bytes

Concurrency Level: 10
Time taken for tests: 5.166 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Non-2xx responses: 1000
Total transferred: 659912 bytes
HTML transferred: 169000 bytes
Requests per second: 193.59 [#/sec] (mean)
Time per request: 51.657 [ms] (mean)
Time per request: 5.166 [ms] (mean, across all concurrent requests)
Transfer rate: 124.76 [Kbytes/sec] received

Connection Times (ms)
        min mean[+/-sd] median max
Connect: 4 5 1.2 5 17
Processing: 14 46 26.9 39 219
Waiting: 14 46 26.9 39 219
Total: 19 51 26.9 44 224

Percentage of the requests served within a certain time (ms)
  50% 44
  66% 49
  75% 52
  80% 55
  90% 64
  95% 113
  98% 174
  99% 193
 100% 224 (longest request)

不使用長連線的時候吞吐率為193.59

下面使用長連線:

[[email protected] images]# ab -c10 -n1000 -k cms.dev.paidui.com/images/3gphost.jpg
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking cms.dev.paidui.com (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: Tengine
Server Hostname: cms.dev.paidui.com
Server Port: 80

Document Path: /images/3gphost.jpg
Document Length: 169 bytes

Concurrency Level: 10
Time taken for tests: 3.086 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Non-2xx responses: 1000
Keep-Alive requests: 992
Total transferred: 648975 bytes
HTML transferred: 169000 bytes
Requests per second: 324.08 [#/sec] (mean)
Time per request: 30.856 [ms] (mean)
Time per request: 3.086 [ms] (mean, across all concurrent requests)
Transfer rate: 205.39 [Kbytes/sec] received

Connection Times (ms)
       min mean[+/-sd] median max
Connect: 0 0 0.8 0 7
Processing: 12 31 21.7 27 232
Waiting: 12 31 21.7 27 232
Total: 12 31 22.2 27 238

Percentage of the requests served within a certain time (ms)
  50% 27
  66% 31
  75% 34
  80% 35
  90% 40
  95% 46
  98% 53
  99% 220
 100% 238 (longest request)

使用長連線的吞吐率為324,除此之外,Keep-Alive request為992,即使用長連線的有992個請求,也就是說有992個請求重用同一個TCP連線。

參考資料

《PHP核心技術與最佳實踐》的第11章 高效能網站架構方案

相關推薦

壓力測試ab用法原創.md

簡介 ab(Apache Bench)是Apache附帶的壓力測試軟體,容易使用,功能完全能夠滿足我們的要求,安裝apache時會自帶該壓力測試軟體 引數說明 ab自帶的引數說明: [[email protected] images]#

MySQL使用sysbench對MySQL進行壓力測試

usr with sleep library val repos then plot 停止 1.背景 ? 出自percona公司,是一款多線程系統壓測工具,可以根據影響數據庫服務器性能的各種因素來評估系統的性能。例如,可以用來測試文件IO,操作系統調度器,內存分配和傳輸

開發工具壓力測試:2、Jmeter的安裝使用(TCP測試

一、工具介紹         Apache JMeter是Apache組織開發的基於Java的壓力測試工具,用於對軟體做壓力測試,它最初被設計用於Web應用測試但後來擴充套件到其他測試領域。 它可以用於測試靜態和動態資源例如靜態檔案、Java小服務程式

高併發壓力測試 java.io.IOException: Too many open files解決方案

 對作業系統做相關的設定,增加最大檔案控制代碼數量。Linux在Linux核心2.4.x中需要修改原始碼,然後重新編譯核心才生效。編輯Linux核心原始碼中的 include/linux/fs.h檔案,將 NR_FILE 由8192改為65536,將NR_RESERVED_FILES 由10 改為 128。編

jmeter3.2介面測試壓力測試示例1使用者登入CSV Data Set Config

1、post因為是使用者登入介面,所以其中測試資料檔案為使用者名稱和密碼:CSV Data Set Config:被用來從檔案中讀取資料,並將它們分割儲存到變數中,適合處理多變數。如:登入,在文字文件內把使用者名稱和密碼引數化,執行操作時,會自動迴圈讀取文本里的使用者名稱和密

apache自帶的ab壓力測試工具用法詳解

ab是apache自帶的一個很好用的壓力測試工具,當安裝完apache的時候,就可以在bin下面找到ab 1 我們可以模擬100個併發使用者,對一個頁面傳送1000個請求 ./ab -n1000 -c100 http://www.baidu.com 其中-n代表請求數,

CentOS壓力測試 ab 命令安裝與使用

evel 發送 詳解 ria 括號 nco csv rate normal Apache安裝包中自帶的壓力測試工具 Apache Benchmark(簡稱ab) 簡單易用,這裏就采用 ab作為壓力測試工具了。 1.獨立安裝 ab運行需要依賴apr-util包,安裝命令為:

POLARDB資料庫的實踐與測試

POLARDB架構簡介 PolarDB是阿里雲ApsaraDB資料庫團隊研發的基於雲端計算架構的下一代關係型資料庫(暫時僅支援MySQL,PostgreSQL正在緊鑼密鼓的開發中),其最大的特色是計算節點(主要做SQL解析以及儲存引擎計算的伺服器)與儲存節點(主

apache壓力測試ab命令使用及結果判斷

模擬1000個請求,600個併發,加上-r引數可防止出現:apr_socket_recv "connection reset by peer" 錯誤# ab -r -n 1000 -c 600 http://192.168.15.55/test/big/index.php This is ApacheBenc

伺服器API壓力測試 -ab工具

最近對伺服器的某些api進行效能測試,我們關注的主要指標就是系統吞吐量。 第三節看看就好,很久前寫的。 1 系統吞吐量的簡單介紹 一個系統的吞度量(承壓能力)與request對CPU的消耗、外部介面、IO等等緊密關聯。 單個reqeust 對CPU消耗越高,

工具http_load與Ab

http_load簡介http_load以並行複用的方式執行,用以測試Web伺服器的吞吐量與負載。但是它不同於大多數壓力測試工具,其可以以一個單一的程序執行,這樣就不會把客戶機搞死,還可以測試HTTPS類的網站請求。關於http_load的詳細資訊參見這裡,點選這裡下載。安裝

ApacheApache ab壓力測試工具Window下載和用法詳解

enc ons 所有 The 產生 ima 腳本 數據 等待 ab是apache自帶的網站壓力測試工具。 使用起來非常的簡單和方便。 不僅僅是可以apache服務器進行網站訪問壓力測試,還可以對其他類型的服務器進行壓力測試。 比如nginx,tomcat,IIS等 首先當然

後臺測試手把手教你jmeter

異常 等於 spl 分別是 觀察 路徑 string gre block 我知道我遲早是要踏上了後臺測試之路的,只是沒想到來的這麽突然。新接手了一個項目,在第一版發出後,產品需要做運營活動拉量,因為我擔心突然的流量湧入是否會對後臺造成壓力呢?因此決定做一下壓測:   下面就

Apache從Apache官網下載windows版apache伺服器,並用AB進行壓力測試

1、下載穩定版2.2.31     http://httpd.apache.org/ 2.2.*和2.4.*區別?     httpd-2.2.x(prefork)     httpd-2.4.x(event) 編譯時可以使用--with-mpm=prefork手動指定

AB 壓力測試工具ApacheBench ab引數分析

首先通過uptime檢視當前負載情況, 通過watch uptime檢視實時負載,觀察負載下降情況 Apache服務自帶了應該用於壓力測試的工具ab(ApacheBench),對應做一些簡單的壓力測試,它完全能夠勝任,本文主要介紹,在centos中不安裝Apache的情況下,安裝ab 1,ab執行的

shell編寫一個簡單的jmeter自動化腳本

image tac vbo 用戶數 osx dot png das uvc 在公司做壓力測試也挺長時間了,每次測試前環境數據準備都需要話費較長時間,所以一直在考慮能不能將整個過程實現自動化進行,於是就抽空寫了一個自動化腳本,當然這個腳本目前功能十分簡陋,代碼也不完善,很有很

Appium測試Android混合應用時,第二次切換到WebView失敗

源碼 drivers asc 切換 ole setup client module already 要解決的問題:Appium測試Android混合應用時,第二次切換到WebView時失敗 原因分析:在用Appium測試Android混合應用時,當程序第一次切換到WebV

JMeter完成一個java請求的

span 依賴 壓測 雙擊 led long urn 相關 記錄 JMeter完成java請求的壓力測試詳解以及問題總結 原文地址:http://www.cnblogs.com/zhaoxd07/p/4895224.html 作者:KK_Yolan

原始碼剖析Webbench —— 簡潔而優美的壓力測試工具

      Webbench 是一個古老而著名的網站壓力測試工具,簡單而實用。如果你不清楚你的網站能承受多大的壓力,或者你想分析對比兩個網站的效能,webbench 再好用不過了。      Gitbub 地址:點我  

Apache ab壓力測試工具Window下載和用法詳解

ab是apache自帶的網站壓力測試工具。 使用起來非常的簡單和方便。 不僅僅是可以apache伺服器進行網站訪問壓力測試,還可以對其他型別的伺服器進行壓力測試。 比如nginx,tomcat,IIS等 首先當然是下載安裝了。 在這裡只講window下在下載安裝 官方下載地址:,(htt