您的位置:首页 > 运维架构 > 网站架构

网站 压力测试工具 Siege,webbench,ab

2009-08-06 15:53 429 查看
http://hi.baidu.com/qiaoyuetian/blog/item/faa914a24b0219aacaefd078.html

网站做好了,当然要做测试,压力测试是测试中重要的环节。
介绍下基于linux的3款压力测试工具:Siege,webbench,ab
1.Siege
一款开源的压力测试工具,可以根据配置对一个WEB站点进行多用户的并发访问,记录每个用户所有请求过程的相应时间,并在一定数量的并发访问下重复进行。
获取:http://www.joedog.org/
官方提供ftp下载

解压:
# tar -zxf siege-latest.tar.gz
进入解压目录:
# cd siege-2.65/
安装:
#./configure ; make
#make install

使用
siege -c 200 -r 10 -f example.url
-c是并发量,-r是重复次数。 url文件就是一个文本,每行都是一个url,它会从里面随机访问的。

example.url内容:
http://www.taoav.com http://www.tuhaoduo.com http://www.tiaonv.com
结果说明
Lifting the server siege… done.
Transactions: 3419263 hits //完成419263次处理
Availability: 100.00 % //100.00 % 成功率
Elapsed time: 5999.69 secs //总共用时
Data transferred: 84273.91 MB //共数据传输84273.91 MB
Response time: 0.37 secs //相应用时1.65秒:显示网络连接的速度
Transaction rate: 569.91 trans/sec //均每秒完成 569.91 次处理:表示服务器后
Throughput: 14.05 MB/sec //平均每秒传送数据
Concurrency: 213.42 //实际最高并发数
Successful transactions: 2564081 //成功处理次数
Failed transactions: 11 //失败处理次数
Longest transaction: 29.04 //每次传输所花最长时间
Shortest transaction: 0.00 //每次传输所花最短时间

2.webbench

获取并安装
wget http://home.tiscali.cz:8080/~cz210552/distfiles/webbench-1.5.tar.gz tar zxvf webbench-1.5.tar.gz
cd webbench-1.5
make && make install
如果找不到源就网上搜个吧

使用:
webbench -c 500 -t 30 http://www.taoav.com 参数说明:-c表示并发数,-t表示时间(秒)
4测试结果示例:
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.

Benchmarking: GET http://www.taoav.com 500 clients, running 30 sec.

Speed=3230 pages/min, 11614212 bytes/sec.
Requests: 1615 susceed, 0 failed.

3.ab
apache自带测试工具,在apache2的bin目录里

测试例子: ab -n 10000 -c 100 -t 10 http://www.taoav.com/index.php 参数: -n 表示请求总数, -c 表示并发数. -t 表示请求时间限制

以下为结果
Server Software: Apache/2.0.53
Server Hostname: www.taoav.com
Server Port: 80

Document Path: /index.php
Document Length: 17998 bytes

Concurrency Level: 100
Time taken for tests: 660.930623 seconds
Complete requests: 10000
Failed requests: 0
Write errors: 0
Total transferred: 181850000 bytes
HTML transferred: 179980000 bytes
Requests per second: 15.13 [#/sec] (mean)
Time per request: 6609.306 [ms] (mean)
Time per request: 66.093 [ms] (mean, across all concurrent requests)
Transfer rate: 268.69 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 15 117.6 0 1730
Processing: 436 6564 1142.2 6517 15395
Waiting: 340 4164 1512.2 3906 14973
Total: 436 6579 1143.4 6526 15395

Percentage of the requests served within a certain time (ms)
50% 6526
66% 6972
75% 7262
80% 7377
90% 7755
95% 8295
98% 8683
99% 9815
100% 15395 (longest request)

====================================================================
web性能测试的一些小工具
http://blog.chinaunix.net/u2/80794/showart_2076085.html

Web网站的压力测试

1、ab

1)、简介
ab apache自带的简单压力测试工具,非常方便但是测试结果可能会与实际情况有差异,一般用其测试静态
页面

2)、获取
apache自带
3)、安装
系统自带,无需单独安装
4)、使用
命令格式:ab -n 请求总数 -c 并发数 -t 请求时限 要求访问的url
-n 请求总数
-c 并发数
-t 请求时间限制
例如:
ab -n 10000 -c 100 -t 10 http://www.winksi.cn 返回结果:
This is ApacheBench, Version 2.0.40-dev <$Revision: 1.146 $> apache-2.0
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Copyright 2006 The Apache Software Foundation, http://www.apache.org/
Benchmarking www.winksi.cn (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Finished 10000 requests

Server Software: Apache-Coyote/1.1
Server Hostname: www.winksi.cn
Server Port: 80

Document Path: /
Document Length: 0 bytes

Concurrency Level: 100
Time taken for tests: 17.979854 seconds
Complete requests: 10000
Failed requests: 0
Write errors: 0
Non-2xx responses: 10028
Total transferred: 2817868 bytes
HTML transferred: 0 bytes
Requests per second: 556.18 [#/sec] (mean)
Time per request: 179.799 [ms] (mean)
Time per request: 1.798 [ms] (mean, across all concurrent requests)
Transfer rate: 153.00 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 32 32.1 22 244
Processing: 38 145 35.6 137 299
Waiting: 2 84 45.9 75 255
Total: 43 177 43.0 171 384

Percentage of the requests served within a certain time (ms)
50% 171
66% 194
75% 208
80% 215
90% 235
95% 252
98% 276
99% 299
100% 384 (longest request)

2、webbench

1)、简介
webbench是linux下的一个网站测试工具,最多可以模拟3万并发连接去测试一个网站负载能力;
2)、获取
可以在以下地址下载到:http://home.tiscali.cz:8080/~cz210552/distfiles/webbench-1.5.tar.gz
3)、安装
[root@byheart software]# tar -zxvf webbench-1.5.tar.gz #解压
[root@byheart software]# cd webbench-1.5 #进入webbench-1.5目录
[root@byheart webbench-1.5]# make && make install #编译安装
[root@byheart webbench-1.5]# whereis webbench #查看webbench目录
webbench: /usr/local/bin/webbench
4)、使用

命令格式:webbench -c 并发量 -t 时间 需要访问的url
-c 是并发量;
-t 表示时间;

下面是对www.winksi.cn的测试结果:
[root@byheart webbench-1.5]# webbench -c 1000 -t 20 http://www.winksi.cn/ Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.

Benchmarking: GET http://www.winksi.cn/ 1000 clients, running 20 sec.

Speed=3042 pages/min, 23396 bytes/sec.
Requests: 1014 susceed, 0 failed.

注意:url一定要以http://开头然后以/结尾,否则会报出url无效

3、siege

1)、简介
一款开源的压力测试工具,可以根据配置对一个WEB站点进行多用户的并发访问,记录每个用户所有请求过
程的相应时间,并在一定数量的并发访问下重复进行。

2)、获取 http://www.joedog.org/
3)、安装
[root@localhost software]# tar -zxvf siege-2.69.tar.gz #解压
[root@localhost software]# cd siege-2.69
[root@localhost siege-2.69]# ./configure --prefix=/usr/local/siege #配置安装目录
[root@localhost siege-2.69]# make && make install #编译安装

注意:安装是会提示一下错误,
make[3]: Entering directory `/usr/local/software/siege-2.69/doc'
/usr/bin/install: cannot create regular file `/usr/local/siege/etc/siegerc': No such file or
directory
make[3]: *** [install-exec-hook] Error 1
make[3]: Leaving directory `/usr/local/software/siege-2.69/doc'
make[2]: *** [install-exec-am] Error 2
make[2]: Leaving directory `/usr/local/software/siege-2.69/doc'
make[1]: *** [install-am] Error 2
make[1]: Leaving directory `/usr/local/software/siege-2.69/doc'
make: *** [install-recursive] Error 1
解决办法是:mkdir -p /usr/local/siege/etc/siegerc 建立这样一个目录就可以继续向下安装的。

4)、使用

命令格式:siege -c 并发量 -r 重复次数 -f urllist文件
urllist格式: http://www.taoav.com http://www.tuhaoduo.com http://www.tiaonv.com 结果说明:
Lifting the server siege… done.
Transactions: 3419263 hits //完成419263次处理
Availability: 100.00 % //100.00 % 成功率
Elapsed time: 5999.69 secs //总共用时
Data transferred: 84273.91 MB //共数据传输84273.91 MB
Response time: 0.37 secs //相应用时1.65秒:显示网络连接的速度
Transaction rate: 569.91 trans/sec //均每秒完成 569.91 次处理:表示服务器后
Throughput: 14.05 MB/sec //平均每秒传送数据
Concurrency: 213.42 //实际最高并发数
Successful transactions: 2564081 //成功处理次数
Failed transactions: 11 //失败处理次数
Longest transaction: 29.04 //每次传输所花最长时间
Shortest transaction: 0.00 //每次传输所花最短时间

4、http_load

1)、简介
这个程序非常小解压后100k,http_load以并行复用的方式运行,用以测试web服务器的吞吐量与负载。但
是它不同于大多数压力测试工具,它可以以一个单一的进程运行,一般不会把客户机搞死。可以可以测试
HTTPS类的网站请求。

2)、获取
可以到http://www.acme.com/software/http_load/http_load-12mar2006.tar.gz下载。

3)、安装
[root@localhost software]# tar -zxvf http_load-12mar2006.tar.tar #解压
[root@localhost software]# cd http_load-12mar2006
[root@localhost http_load-12mar2006]# mkdir -p /usr/local/man/man1 #安装时会报出没有
前边的目录,所以建立目录/usr/local/man/man1
[root@localhost http_load-12mar2006]# make && make install #安装
[root@localhost http_load-12mar2006]# whereis http_load #查看程序安装目录
http_load: /usr/local/bin/http_load

4)、使用
命令格式:http_load -p 并发访问进程数 -s 访问时间 需要访问的URL list文件
http_load -r 每秒钟访问频率 -s总计的访问时间 需要放问的url list文件
-p 并发访问进程数;
-s 访问时间;
-r 每秒钟的访问频率
-f 总计的访问次数

注意:直接跟url是不行的必须是跟的一个url的文件,文件格式是每一行有一个url,中间不要出现空行否则
会爆 出一下错误:
[root@localhost scripts]# http_load -p 500 -s 60 /home/scripts/urllist
http_load: unknown protocol - www.winksi.cn
例子:
urllist内容:
[root@localhost scripts]# cat urllist http://www.winksi.cn http://www.winksi.com

返回结果

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进行分析,才能得出结论;

5 压力测试模型:
假设支持100w
每个用户每天访问a次 (web.tools.com)
每天次数:100w * a
按照80/20原则,80%的访问集中在20%的时间内
100w * a * 80% / 4.8小时
假设对用户来说每次访问6秒钟是可以接受的
(100w*a*80%/4.8h)*6=测试用并发数据
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐