Web压力测试工具:http_load、webbench、ab、Siege运用要领
前言:常在网络飘,哪有不受刀?做网站的站长说不准哪天得罪了XX人,二话不说直接操着DDOS就上来搞你了,黑不了你,哥就D死你,碰到这样的无赖,还真没办法,因而经常性的给本人的网站做做压力测试,看看服务器的承载能力是很有须要的一件事。
一、http_load
程序非常小,解压后也不到100K
http_load以并行复用的方式运转,用以测试web服务器的吞吐量与负载。但是它不一样于大多数压力测试工
具,它可以以一个单一的进程运转,个别不会把客户机搞死。还可以测试HTTPS类的网站请求。
下载地址:http://soft.vpser.net/test/http_load/http_load-12mar2006.tar.gz
安装很简略
#tar zxvf http_load-12mar2006.tar.gz
#cd http_load-12mar2006
#make && make install
下令格局:http_load -p 并发访问进程数 -s 访问工夫 需要访问的URL文件
参数其实可以自在组合,参数之间的选中并没有什么限定。比方你写成http_load -parallel 5 -seconds
300 urls.txt也是可以的。我们把参数给大家简略注明一下。
-parallel 简写-p :含义是并发的会员进程数。
-fetches 简写-f :含义是总计的访问次数
-rate 简写-p :含义是每秒的访问频率
-seconds简写-s :含义是总计的访问工夫
预备URL文件:urllist.txt,文件格局是每行一个URL,URL最佳超过50-100个测试结果比较好.文件格局
如下:
http://hackerfans.com/xxx.html
http://hackerfans.com/xx.html
例如:
http_load -p 30 -s 60 urllist.txt
参数理解了,我们来看运转一条下令来看看它的返回效果
下令:% ./http_load -rate 5 -seconds 10 urls注明施行了一个延续工夫10秒的测试,每秒的频率为5。
49 fetches, 2 max parallel, 289884 bytes, in 10.0148 seconds5916 mean bytes/connection4.89274
fetches/sec, 28945.5 bytes/secmsecs/connect: 28.8932 mean, 44.243 max, 24.488 minmsecs/first
-response: 63.5362 mean, 81.624 max, 57.803 minHTTP response codes: code 200 -- 49
效果剖析:
1.49 fetches, 2 max parallel, 289884 bytes, in 10.0148 seconds
注明在上面的测试中运转了49个请求,最大的并发进程数是2,总计传输的数据是289884bytes,运转的工夫是10.0148秒
2.5916 mean bytes/connection注明每一连贯均匀传输的数据量289884/49=5916
3.4.89274 fetches/sec, 28945.5 bytes/sec
注明每秒的相应请求为4.89274,每秒通报的数据为28945.5 bytes/sec
4.msecs/connect: 28.8932 mean, 44.243 max, 24.488 min注明每连贯的均匀相应工夫是28.8932 msecs
,最大的相应工夫44.243 msecs,最小的相应工夫24.488 msecs
5.msecs/first-response: 63.5362 mean, 81.624 max, 57.803 min
6、HTTP response codes: code 200 -- 49 注明打开相应页面的类型,要是403的类型过多,那可能
要注意是否系统碰到了瓶颈。
特别注明:
测试效果中主要的目标是 fetches/sec、msecs/connect 这个选项,即服务器每秒能够相应的查询次数,
用这个目标来掂量机能。似乎比 apache的ab正确率要高一些,也更有说服力一些。
Qpt-每秒相应会员数和response time,每连贯相应会员工夫。
测试的效果主要也是看这两个值。当然仅有这两个目标并不能完成对机能的剖析,我们还需要对服务器的
cpu、men进行剖析,才能得出结论
二、webbench
webbench是Linux下的一个网站压力测试工具,最多可以模拟3万个并发连贯去测试网站的负载能力。下载
地址可以到google搜,我这里给出一个
下载地址:http://soft.vpser.net/test/webbench/webbench-1.5.tar.gz
这个程序更小,解压后不到50K,呵呵
安装非常简略
#tar zxvf webbench-1.5.tar.gz
#cd webbench-1.5
#make && make install
会在目前目录生成webbench可施行文件,直接可以运用了
用法:
webbench -c 并发数 -t 运转测试工夫 URL
如:
webbench -c 5000 -t 120 http://hackerfans.com
三、ab
ab是apache自带的一款功能强大的测试工具
安装了apache个别就自带了,
用法可以查看它的注明
$ ./ab
./ab: wrong number of arguments
Usage: ./ab [options] [http://]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
-p postfile File containing data to POST
-T content-type Content-type header for POSTing
-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
-h Display usage information (this message)
参数众多,个别我们用到的是-n 和-c
例如:
./ab -c 1000 -n 100 http://hackerfans.com/index.php
这个表示同时处置1000个请求并运转100次index.php文件.
四、Siege
一款开源的压力测试工具,可以依据配置对一个WEB站点进行多会员的并发访问,记载每个会员所有请求历程的响应工夫,并在一定数目的并发访问下反复进行。
官方:http://www.joedog.org/
Siege下载:http://soft.vpser.net/test/siege/siege-2.67.tar.gz
解压:
# tar -zxf siege-2.67.tar.gz
进入解压目录:
# cd siege-2.67/
安装:
#./configure ; make
#make install
运用
siege -c 200 -r 10 -f example.url
-c是并发量,-r是反复次数。 url文件就是一个文本,每行都是一个url,它会从里面随机访问的。
example.url内容:
http://hackerfans.com
http://soft.hackerfans.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 //每次传输所花最短工夫