Image 01 Image 02

Web压力测试工具介绍

Posted on 2nd 三月 2010 by cbc
0

1 http_load

1.1 官方网站
  • 描述:
    • http_load runs multiple http fetches in parallel, to test the throughput of a web server. However unlike most such test clients, it runs in a single process, so it doesn’t bog down the client machine. It can be configured to do https fetches as well.
    • You give it a file containing a list of URLs that may be fetched, a flag specifying how to start connections (either by rate or by number of simulated users), and a flag specifying when to quit (either after a given number of fetches or a given elapsed time). There are also optional flags for checksums, throttling, random jitter, and progress reports.
  • 地址:
1.2 具体操作及说明
  • 常用样例
http_load -parallel 5 -fetches 1000 urls.txt  http_load -rate 2 -seconds 300 urls.txt
  • 样例含义
    • -parallel 简写-p :含义是并发的用户进程数。
    • -fetches 简写-f :含义是总计的访问次数
    • -rate 简写-r :含义是每秒的访问频率
    • -seconds简写-s :含义是总计的访问时间
    • urls.txt 是一个url 列表,每个url 单独的一行;不可以直接跟一个url,有些博客主说的可以跟一个url是错误的说法。
  • 返回结果
http_load -rate 5 -seconds 10 urls  49 fetches, 2 max parallel, 289884 bytes, in 10.0148 seconds  5916 mean bytes/connection  4.89274 fetches/sec, 28945.5 bytes/sec  msecs/connect: 28.8932 mean, 44.243 max, 24.488 min  msecs/first-response: 63.5362 mean, 81.624 max, 57.803 min  HTTP response codes:  code 200 -- 49
  • 结果含义
    • 49 fetches, 2 max parallel, 289884 bytes, in 10.0148 seconds
    • 说明在上面的测试中运行了49个请求,最大的并发进程数是2,总计传输的数据是289884bytes,运行的时间是10.0148秒
    • 5916 mean bytes/connection
    • 说明每一连接平均传输的数据量289884/49=5916
    • 4.89274 fetches/sec, 28945.5 bytes/sec
    • 说明每秒的响应请求为4.89274,每秒传递的数据为28945.5 bytes/sec
    • msecs/connect: 28.8932 mean, 44.243 max, 24.488 min
    • 说明每连接的平均响应时间是28.8932 msecs,最大的响应时间44.243 msecs,最小的响应时间24.488 msecs
    • msecs/first-response: 63.5362 mean, 81.624 max, 57.803 min
    • HTTP response codes: code 200 — 49
    • 说明打开响应页面的类型,如果403的类型过多,那可能要注意是否系统遇到了瓶颈。
  • 特殊说明
    • 一般会关注到的指标是fetches/sec、msecs/connect,它们分别对应的常用性能指标参数QPS-每秒响应用户数和response time,每连接响应用户时间。测试的结果主要也是看这两个值。当然仅有这两个指标并不能完成对性能的分析,我们还需要对服务器的cpu、men进行分析,才能得出结论;
    • 如果要测试HTTPS,需要在编译前指定Makefile中 SSL_TREE 的路径:一般为 /usr/usr/local

2 ab

2.1 官方网站
  • 描述:
    • ab is a tool for benchmarking your Apache Hypertext Transfer Protocol (HTTP) server. It is designed to give you an impression of how your current Apache installation performs. This especially shows you how many requests per second your Apache installation is capable of serving.
  • 地址:
2.2 具体操作
  • 常用样例
ab -n 1000 -c 50 http://www.domain.com/myapp.php
  • 样例说明
    • ab将同时向http://www.domain.com/myapp.php发出50个并发请求,共发出1000次。
  • 返回结果
Server Software:        nginx/0.6.25Server Hostname:        www.domain.comServer Port:            80

Document Path:          /myapp.phpDocument Length:        37899 bytes

Concurrency Level:      100Time taken for tests:   26.507540 secondsComplete requests:      2000Failed requests:        14   (Connect: 0, Length: 14, Exceptions: 0)Write errors:           0Keep-Alive requests:    0Total transferred:      75931178 bytesHTML transferred:       75439670 bytesRequests per second:    75.45 [#/sec] (mean)Time per request:       1325.377 [ms] (mean)Time per request:       13.254 [ms] (mean, across all concurrent requests)Transfer rate:          2797.36 [Kbytes/sec] received

Connection Times (ms)              min  mean[+/-sd] median   maxConnect:       24  640 1310.9     34    7478Processing:    86  590 2230.9    124   23256Waiting:        0   55 207.7     41    8292Total:        112 1230 2501.0    169   23304
    • 部分返回字串省略,这里只表示关键部分;
    • myapp.php每秒钟可以处理的请求数为75.45个
  • 特殊说明
    • 若将请求数增加,看看服务器能否处理更大的压力,需要调节Apache的 MaxClients、ThreadsPerChild、MaxThreadsPerChild 等参数,基于httpd.conf中的MPM模块选择。
    • 若本地服务器不是Apache,请使用其它测试方法。
2.3 文档说明

3 Siege

web压力测试工具——Siege(英文原意:围攻)。

下载安装:

wget ftp://ftp.joedog.org/pub/siege/siege-latest.tar.gztar

zxvf siege-latest.tar.gzcd siege-2.67

./configure

make && make install安装完成后,就可以开始进行压力测试了

修改siege配置

vi ~/.siegerc

调整:

verbose = false

concurrent = 50

delay = 1

internet = true

benchmark = true

siege参数介绍:

* -cNUM

设置并发的用户(连接)数量,比如-c10,设置并发10个连接。默认的连接数量可以到~/.siegerc中查看,指令为concurrent = x,前面咱们已经调整了默认并发连接为50。

* -rNUM

(repetitions),重复数量,即每个连接发出的请求数量,设置这个的话,就不需要设置-t了。对应.siegerc配置文件中的reps = x指令

* -tNUM

(time),持续时间,即测试持续时间,在NUM时间后结束,单位默认为分,比如-t10,那么测试时间为10分钟,-t10s,则测试时间为10秒钟。对应.siegerc中的指令为time = x指令

* -b

(benchmark),基准测试,如果设置这个参数的话,那么delay时间为0。在.siegerc中咱们修改为默认开启。

* -f url.txt

(file),这是url列表文件。对应.siegerc配置文件中的file = x指令

siege -c 20 -r 2 -f www.chedong.com.url

参数说明:

-c 20 并发20个用户

-r 2 重复循环2次

-f www.chedong.com.url 任务列表:URL列表

输出样例:

** Siege 2.59

** Preparing 20 concurrent users for battle. 这次“战斗”准备了20个并发用户

The server is now under siege.. done. 服务在“围攻”测试中:

Transactions: 40 hits 完成40次处理

Availability: 100.00 % 成功率

Elapsed time: 7.67 secs 总共用时

Data transferred: 877340 bytes 共数据传输:877340字节

Response time: 1.65 secs 相应用时1.65秒:显示网络连接的速度

Transaction rate: 5.22 trans/sec 平均每秒完成5.22次处理:表示服务器后台处理的速度

Throughput: 114385.92 bytes/sec 平均每秒传送数据:114385.92字节

Concurrency: 8.59 最高并发数 8.59

Successful transactions: 40 成功处理次数

Failed transactions: 0 失败处理次数如果你的WEB服务器用的是Apache,请不要将并发数设为大于200。



Leave a reply...