51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

查看: 2017|回复: 2
打印 上一主题 下一主题

吞吐率和压力测试

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2018-2-28 14:19:07 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
吞吐率指的是单位时间内服务器处理的请求数,通常使用 reqs/s (服务器每秒处理的请求数量)来
表示。
吞吐率只描述了服务器在实际运行期间单位时间内处理的请求数,而我们更加关心的是服务器并发
处理能力的上限,即单位时间内服务器能够处理的最大请求数(即最大吞吐率)。但在测试时,很
难调动足够多的人测试服务器的最大吞吐率。所以,需要使用某些方法模拟足够数目的并发用户数,
这种方法称为“压力测试”。
压力测试的工具很多,如LoadRunner、JMeter和ab等。由于LoadRunner和JMeter使用起来过于复杂,
故这里我们介绍一种比较简单的压力测试工具ab。
ab(Apache Bench)是Apache附带的一个压力测试软件。它操作起来比较简单,功能基本能够满足
我们的要求。
打开cmd,切换至Apache的bin目录(如:我的是 E:\xampp\apache\bin )
cd E:\xampp\apache\bin
ab -h          // 打印出ab工具的使用信息
  1. Usage: ab [options] [http://]hostname[:port]/path  
  2. Options are:  
  3.     -n requests     Number of requests to perform  
  4.     -c concurrency  Number of multiple requests to make at a time  
  5.     -t timelimit    Seconds to max. to spend on benchmarking  
  6.                     This implies -n 50000  
  7.     -s timeout      Seconds to max. wait for each response  
  8.                     Default is 30 seconds  
  9.     -b windowsize   Size of TCP send/receive buffer, in bytes  
  10.     -B address      Address to bind to when making outgoing connections  
  11.     -p postfile     File containing data to POST. Remember also to set -T  
  12.     -u putfile      File containing data to PUT. Remember also to set -T  
  13.     -T content-type Content-type header to use for POST/PUT data, eg.  
  14.                     'application/x-www-form-urlencoded'  
  15.                     Default is 'text/plain'  
  16.     -v verbosity    How much troubleshooting info to print  
  17.     -w              Print out results in HTML tables  
  18.     -i              Use HEAD instead of GET  
  19.     -x attributes   String to insert as table attributes  
  20.     -y attributes   String to insert as tr attributes  
  21.     -z attributes   String to insert as td or th attributes  
  22.     -C attribute    Add cookie, eg. 'Apache=1234'. (repeatable)  
  23.     -H attribute    Add Arbitrary header line, eg. 'Accept-Encoding: gzip'  
  24.                     Inserted after all normal header lines. (repeatable)  
  25.     -A attribute    Add Basic WWW Authentication, the attributes  
  26.                     are a colon separated username and password.  
  27.     -P attribute    Add Basic Proxy Authentication, the attributes  
  28.                     are a colon separated username and password.  
  29.     -X proxy:port   Proxyserver and port number to use  
  30.     -V              Print version number and exit  
  31.     -k              Use HTTP KeepAlive feature  
  32.     -d              Do not show percentiles served table.  
  33.     -S              Do not show confidence estimators and warnings.  
  34.     -q              Do not show progress when doing more than 150 requests  
  35.     -l              Accept variable document length (use this for dynamic pages)  
  36.     -g filename     Output collected data to gnuplot format file.  
  37.     -e filename     Output CSV file with percentages served  
  38.     -r              Don't exit on socket receive errors.  
  39.     -m method       Method name  
  40.     -h              Display usage information (this message)  
复制代码
ab的选项比较多,常用的有以下几个:
n   在测试会话中执行的请求的数目,默认执行一个请求。
c   要创建的并发用户数,默认创建一个用户数。
t   等待Web服务器响应的最大时间(单位:秒),默认没有时间限制
k   使用Keep Alive(长连接)特性
c   对请求附加一个Cookie,形式为name=value

下面使用 ab 进行一次压力测试:
ab -n1000 -c10 demo.com/index.php
输出内容如下:
  1. This is ApacheBench, Version 2.3 <$Revision: 1604373 [        DISCUZ_CODE_7        ]gt;  
  2. Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/  
  3. Licensed to The Apache Software Foundation, http://www.apache.org/  
  4.   
  5. Benchmarking demo.com (be patient)  
  6. Completed 100 requests  
  7. Completed 200 requests  
  8. Completed 300 requests  
  9. Completed 400 requests  
  10. Completed 500 requests  
  11. Completed 600 requests  
  12. Completed 700 requests  
  13. Completed 800 requests  
  14. Completed 900 requests  
  15. Completed 1000 requests  
  16. Finished 1000 requests  
  17.   
  18. Server Software:        Apache/2.4.10  
  19. Server Hostname:        demo.com  
  20. Server Port:            80  
  21.   
  22. Document Path:          /index.php  
  23. Document Length:        36 bytes  
  24.   
  25. Concurrency Level:      10  
  26. Time taken for tests:   0.452 seconds  
  27. Complete requests:      1000  
  28. Failed requests:        0  
  29. Total transferred:      254000 bytes  
  30. HTML transferred:       36000 bytes  
  31. Requests per second:    2210.43 [#/sec] (mean)  
  32. Time per request:       4.524 [ms] (mean)  
  33. Time per request:       0.452 [ms] (mean, across all concurrent requests)  
  34. Transfer rate:          548.29 [Kbytes/sec] received  
  35.   
  36. Connection Times (ms)  
  37.               min  mean[+/-sd] median   max  
  38. Connect:        0    0   1.8      0      16  
  39. Processing:     0    4   7.0      0      31  
  40. Waiting:        0    4   6.8      0      31  
  41. Total:          0    4   7.1      0      31  
  42.   
  43. Percentage of the requests served within a certain time (ms)  
  44.   50%      0  
  45.   66%      0  
  46.   75%     16  
  47.   80%     16  
  48.   90%     16  
  49.   95%     16  
  50.   98%     16  
  51.   99%     16  
  52. 100%     31 (longest request)  
复制代码
从测试结果可以看出,吞吐率为2210.43reqs/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:所有请求的响应数据中正文数据的长度总和。
Requests per second:Web服务器的吞吐率,等于Complete requests/Time taken for tests。
Time per request:用户平均每个请求的等待时间。
Transfer rate:这些请求在单位时间内从服务器取得的数据长度,等于Total transferred/Time taken for tests。

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

本版积分规则

关闭

站长推荐上一条 /1 下一条

小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

GMT+8, 2024-5-11 19:40 , Processed in 0.068882 second(s), 22 queries .

Powered by Discuz! X3.2

© 2001-2024 Comsenz Inc.

快速回复 返回顶部 返回列表