3月 15

网站压力测试微型工具技术备忘

[记录整理:张子萌 2010-03-15]

经常对服务器单个模块做非专业性压力测试,所以学习了两个小巧大的工具,做技术备忘。
如果需要做比较详细数据请使用LoadRunner、QALoad、JMeter等专业工具。

一款是apahe自带的ab工具。一款是webbench。

1.apache自带ab工具

此工具为apache自带可以显示较多测试信息,
http://apache.freelamp.com/httpd/httpd-2.2.15.tar.gz
以下编译只为获得ab工具,不作为apache安装使用,编译时添加安装路径,是为方便
不小心安装后删除方便。
# cd httpd-2.2.15
# ./configure –prefix=/usr/local/apache_ab
# make
# cd support/.libs/
在目录下已经可以看到ab程序了,ab程序主要参数解释如下

格式: ./ab [options] [http://]hostname[:port]/path
Options are:
-n requests Number of requests to perform
# 在默认会话中发送请求的个数,默认时为50000
-c concurrency Number of multiple requests to make
# 一次请求所产生的次数
-t timelimit Seconds to max. wait for responses
# 测试所进行的最大秒数。默认时,没有时间c和n参数限制请求完毕为止。
-b windowsize Size of TCP send/receive buffer, in bytes
# 发送和接受包大小
-w Print out results in HTML tables
# 以HTML表的格式输出结果
-v verbosity How much troubleshooting info to print
# 打印头部信息,参数为输出级别1-4
-i Use HEAD instead of GET
# 使用head请求不是get请求
-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.
# web使用庄户密码
-P attribute Add Basic Proxy Authentication, the attributes
are a colon separated username and password.
# 对代理使用账户密码
-X proxy:port Proxyserver and port number to use
# 使用代理服务器

开始测试主要使用参数也就两个,以下对部分结果做解释
# ./ab -c 1000 -n 1000 http://172.192.1.100/
# url结尾如不是文件(如:index.html),一定要增加“/”
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 172.192.1.100 (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests

Server Software: nginx
Server Hostname: 172.192.1.100
Server Port: 80

Document Path: /
Document Length: 2731 bytes
# 传输单个文档大小

Concurrency Level: 1000
# 并发数
Time taken for tests: 3.320 seconds
# 本次测试持续的时间
Complete requests: 1000
# 本次测试完成请求数量
Failed requests: 0
# 本此测试失败数量
Write errors: 0
Total transferred: 3039360 bytes
HTML transferred: 2749800 bytes
Requests per second: 301.18 [#/sec] (mean)
# 每秒钟处理数量的平均值
Time per request: 3320.263 [ms] (mean)
# 处理请求的平均响应时间
Time per request: 3.320 [ms] (mean, across all concurrent requests)
# 每个请求实际运行时间的平均值
Transfer rate: 893.94 [Kbytes/sec] received
# 平均每秒网络流量

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 200 701.6 26 3000
Processing: 1 275 373.3 254 3280
Waiting: 1 275 373.2 254 3280
Total: 1 475 735.5 302 3316
# 网络响应时间,主要为connect时间。
# 以下为请求处理时间的分布

Percentage of the requests served within a certain time (ms)
50% 302
66% 348
75% 362
80% 369
90% 410
95% 3008
98% 3016
99% 3311
100% 3316 (longest request)

2.webbench工具
获取地址:
http://blog.s135.com/soft/linux/webbench/webbench-1.5.tar.gz
获取版本进行编译
# tar zxvf webbench-1.5.tar.gz
# cd webbench-1.5
# make
在本目录下可以看到webbench软件,webbench程序主要参数如下
格式:webbench [option]… URL
-f|–force Don’t wait for reply from server.
-r|–reload &
nbsp; Send reload request – Pragma: no-cache.
-t|–time Run benchmark for seconds. Default 30.
-p|–proxy Use proxy server for request.
-c|–clients Run HTTP clients at once. Default one.
-9|–http09 Use HTTP/0.9 style requests.
-1|–http10 Use HTTP/1.0 protocol.
-2|–http11 Use HTTP/1.1 protocol.
–get Use GET request method.
–head Use HEAD request method.
–options Use OPTIONS request method.
–trace Use TRACE request method.
-?|-h|–help This information.
-V|–version Display program version.

使用100个并发持续5秒钟
#./webbench -c 100 -t 5 http://www.google.com/
Webbench – Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.

Benchmarking: GET http://www.google.com/
100 clients, running 5 sec.

Speed=36 pages/min, 4289 bytes/sec.
Requests: 3 susceed, 0 failed.

3.两款工具对比

ab工具显示测试数据比webbench详细。但是ab可测试并发量小于webbench,ab并发使用
不要超过1024(主要受到apache配置和系统资源限制),webbench并发使用数量不要超过10000,
如果超出此方为可能会引起测试机短暂假死现象,且不能获得返回数据。此两宽小型软件已经
够用,对于网上常见的Siege,http_load等就不看了。