1. 程式人生 > >壓力測試 apache ab工具使用說明

壓力測試 apache ab工具使用說明

ab

ab工具使用說明

1 . 安裝ab工具命令

sudo apt-get install apache2-utils

2.ab命令參數說明

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

//post文件(包含post數據),同事要設置-T

-p postfile File containing data to POST. Remember also to set -T

-u putfile File containing data to PUT. Remember also to set -T

//為POST設置內容類型頭部

-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

//設置Cookie

-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)

3.使用方法

運行 ab -n 100 -c 10 http://keketour.me/

http://keketour.me/ 網站 進行著100次請求,10個請求同時並發

壓力測試結果

  1. Server Software: lighttpd/1.4.20

  2. Server Hostname: www.meetu.hk

  3. Server Port: 80

  4. Document Path: /

  5. Document Length: 2095 bytes

  6. Concurrency Level: 10

  7. //整個測試持續的時間

  8. Time taken for tests: 3.303 seconds

  9. //完成的請求數量

  10. Complete requests: 100

  11. Failed requests: 0

  12. Write errors: 0

  13. Total transferred: 235200 bytes

  14. HTML transferred: 209500 bytes

  15. //平均每秒處理30個請求

  16. Requests per second: 30.27 [#/sec] (mean)

  17. //平均每個請求處理時間為330毫秒 註:這裏將一次10個並發請求看成一個整體

  18. Time per request: 330.335 [ms] (mean)

  19. //平均每個並發請求處理 時間 為33毫秒

  20. Time per request: 33.034 [ms] (mean, across all concurrent requests)

  21. Transfer rate: 69.53 [Kbytes/sec] received

  22. Connection Times (ms)

  23. min mean[+/-sd] median max

  24. Connect: 51 170 35.9 178 230

  25. Processing: 60 153 64.5 121 263

  26. Waiting: 55 148 64.4 115 258

  27. Total: 235 322 59.9 299 437

  28. Percentage of the requests served within a certain time (ms)

  29. //在這100個請求中有50%在299毫秒內完成

  30. 50% 299

  31. //在這100個請求中有66%在312毫秒內完成

  32. 66% 312

  33. 75% 383

  34. 80% 412

  35. 90% 431

  36. 95% 432

  37. 98% 436

  38. 99% 437

  39. 100% 437 (longest request)

註意:

模擬登陸的時候,只需要設置Cookie:

1.先用賬戶和密碼登錄後,用開發者工具找到標識這個會話的Cookie值(Session ID)記下來

2.如果只用到一個Cookie,那麽只需鍵入命令:

ab -n 100 -c 10 -C jiang_token=3820aab5-a395-48b2-8d2b-87bf47026e78

http://keketour.me/

如果需要多個Cookie,就直接設Header:

ab -n 100 -H “Cookie: Key1=Value1; Key2=Value2” http://keketour.me/

測試API接口 (這裏以添加行程方案為例)

ab -n 10 -c 5 -p /var/www/kkt/post.txt -v 3 -H "Cookie:jiang_token=3820aab5-a395-48b2-8d2b-87bf47026e78;X-Requested-With:XMLHttpRequest" -T application/x-www-form-urlencoded "http://keketour.me/product/tourinfo/savetournameajax"

其中post.txt為post參數文本,內容為

name=壓力測試行程方案&tour_id=0&product_id=1382&_method=PATCH

總結:

ab工具ab小巧簡單,上手學習較快,可以提供需要的基本性能指標,但是沒有圖形化結果,不能監控。因此ab工具可以用作臨時緊急任務和簡單測試。


本文出自 “從前慢” 博客,請務必保留此出處http://onebig.blog.51cto.com/13006327/1981389

壓力測試 apache ab工具使用說明