网站压力测试测试工具

Httperf Autobench OpenWebLoad webbench ab

用三种工具评估server 性能。都用来进行负载测试但使用不同方式:
httperf: HP开发的相当知名的开源工具(只适用于linux) Autobench: Perl wrapper for httperf improving the testing mecha

nisms and

generating detailed reports
OpenWebLoad:小规模的开源负载测试应用;支持Windows 和Linux

每个工具的原理都是:生成大量http请求来clutter the server and study the results.

Httperf
Httperf 是个简单命令行工具可从官方下载:
http://www.hpl.hp.com/research/linux/httperf/. 资源需源码安装: ./configure, make and make install. 安装成功后: [alex@example ~]$ httperf --server 192.168.1.10 --port 80 --uri /index.html --rate 300 --num-conn 30000 --num-call 1 --timeout 5

Replace the values in the command above with your own:
--server:要测试的站点主机名 --uri:要下载的文件路径 --rate:每秒发送请求数量 --num-conn: 连接总数 --num-call: How many requests should be sent per connection --timeout:一个请求被认为丢失前的秒数

In this example, httperf will download http://192.168.1.10/index.html repeatedly, 300 times per second, resulting in a total of 30,000 requests.

结果显示了the response times 和 the amount of successful requests. 如果成功率为100 percent 或响应时间接近0 ms, 增加请求速度再测试直到server显得很弱。一旦结果看起来 不太好就调整适当的配置指令然后再测试.

Autobench
Autobench 是a Perl 脚本使得httperf更高效—它持续不断的测试且自动增加请求速率直到 server饱和。Autobench的一个有趣特性是生成 a .tsv报告(你可使用各种应用打开它来生成图 表) 可从以下站点下载: http://www.xenoclast.org/autobench/ . 解压三部曲安装 Although it supports testing of multiple hosts at once, we will only be using the single host test for more simplicity尽管支持一次测试多个主机出于简单只用于单一主机测试。命 令类似与httperf:
[alex@example ~]$ autobench --single_host --host1 192.168.1.10 --uri1 /index.html --quiet --low_rate 20 --high_rate 200 --rate_step 20 --num_call 10 --num_conn 5000 --timeout 5 --file results.tsv

The switches can be configured as follows:
--host1: 要测试站点的主机名 --uri1:要下载的文件的路径. --quiet: 不显示httperf 信息. --low_rate:测试开始时每秒连接数. --high_rate:测试尾声时每秒连接数. --rate_step:每个测试后增加的连接数. --num_call: How many requests should be sent per connection. --num_conn: 连接总数. --timeout: The number of seconds elapsed before a request is considered lost.

--file:按指定的那样输出结果(.tsv file).

一旦测试结束你可以用某一应用如excel导入.tsv结尾的文件。 以下是测试后生成的图表 (note that the report file contains up to 10 series of statistics):

由标得出,this test server supports up to 600 requests per second without a loss. Past this limit, some connections get dropped as Nginx cannot handle the load. It stills gets up to over 1,500 successful requests per second at step 9.
Warning: 测试是在虚拟机上执行的不能反应生产服务器上的实际性能

OpenWebLoad
OpenWebLoad免费开源.linux和windows平台都可用You may download it from its official website: http://openwebload.sourceforge.net. Extract the source from the .tar.gz archive, run ./configure, make and make install. 比前两个工具更简单:
[alex@example ~]$ openload example.com/index.html 10

第一个参数是要测试的网址. 第二个参数是打开的连接数量.

每秒都会产生一个新的结果行.连续发送请求除非按下enter键,然后显示结果摘要. 输出结果 解释:

Tps (transactions per second): A transaction相对于一个完整请求(back and forth) MaTps: Average Tps over the last 20 seconds Resp Time: Average response time for the elapsed second Err (error rate): Errors occur when the server returns a response that is not the expected HTTP 200 OK Count: Total transaction count 调整并发连接数量看效果以找到平衡点.三个不同并发数的测试. The results speak for themselves:
Test 1 Simultaneous connections Transactions per second (Tps) Average response time Test 2 1 67.54 14 ms 20 205.87 91 ms Test 3 1000 185.07 596 ms

太少并发导致低Tps rate但响应时间短;太多并发导致相对高的Tps rate但响应时间非常长, 需要找到折衷点。

webbench 简介 Webbench 是有名的网站压力测试工具,它是由 Lionbridge 公司 (http://www.lionbridge.com)开发。它的帮助文件和文档请到: www.webbench.com 上查看。 Webbech 能测试处在相同硬件上,不同服务的性能以及不同硬件上同一个服务的 运行状况。webBech 的标准测试可以向我们展示服务器的两项 内容:每秒钟相 应请求数和每秒钟传输数据量。webbench 不但能具有便准静态页面的测试能力, 还能对动态页面(ASP,PHP,JAVA,CGI)进 行测试的能力。还有就是他支持对含 有 SSL 的安全网站例如电子商务网站进行静态或动态的性能测试。 二、webbench 安装 (1)在 FreeBSD 下的用 Ports 安装方法: #cd /usr/ports/benchmarks/webbench

#make install clean 记得安装成功以后运行一下 rehash 命令,刷新一下系统命令 #rehash (2)RedHat/CentOS 下的编译安装”的文章">编译安装

下载安装包:wget http://gisblogs.net/upload/softs/webbench-1.5.tar.gz #tar zxf webbench-1.5.tar.gz #cd webbench-1.5 #make && make install 三、webbench 使用 #webbench -? (查看命令帮助)

常用参数说明,-c 表示客户端数,-t 表示时间 测试实例: #webbench -c 500 测试静态图片 #webbench -c 500 -t 30 http://127.0.0.1/test.jpg -t 30 http://127.0.0.1/phpionfo.php

四、webbench 测试结果 Webbench - Simple Web Benchmark 1.5 Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software. Benchmarking: GET http://127.0.0.1/phpionfo.php 500 clients, running 30 sec. Speed=3230 pages/min, 11614212 bytes/sec. Requests: 1615 susceed, 0 failed. ab 是 Apache 超文本传输协议(HTTP)的性能测试工具。其设计意图是描绘当前所安装的 Apache 的执行性能,
主要是显示你安装的 Apache 每秒可以处理多少个请求。

语法
ab [ -A auth-username:password ] [ -c concurrency ] [ -C cookie-name=value ] [ -d ] [ -e csv-file ] [ -g gnuplot-file ] [ -h ] [ -H custom-header ] [ -i ] [ -k ] [ -n requests ] [ -p POST-file ] [ -P proxy-auth-username:password ] [ -q ] [ -s ] [ -S ] [ -t timelimit ] [ -T content-type ] [ -v verbosity] [ -V ] [ -w ] [ -x <table>-attributes ] [ -X proxy[:port] ] [ -y <tr>-attributes ] [ -z <td>-attributes ] [http://]hostname[:port]/path 选项

-A auth-username:password 向服务器提供基本认证信息。用户名和密码之间由一个":"隔开,并将被以 base64 编码形式发 送。无论服务器是否需要(即是否发送了 401 认证需求代码),此字符串都会被发送。 -c concurrency 一次产生的请求个数。默认是一次一个。 -C cookie-name=value 对请求附加一个"Cookie:"头行。其典型形式是 name=value 的一个参数对。此参数可以重复。 -d 不显示"percentage served within XX [ms] table"消息(为以前的版本提供支持)。 -e csv-file 产生一个逗号分隔(CSV)文件,其中包含了处理每个相应百分比请求(从 1%到 100%)所需要的 相应百分比时间(以微秒为单位)。由于这种格式已经"二进制化",所以比"gnuplot"格式更有用。 -g gnuplot-file 把所有测试结果写入一个"gnuplot"或者 TSV(以 Tab 分隔)文件。此文件可以方便地导入到 Gnuplot, IDL, Mathematica, Excel 中。其中的第一行为标题。 -h 显示使用方法的帮助信息。 -H custom-header 对请求附加额外的头信息。此参数的典型形式是一个有效的头信息行,其中包含了以冒号分隔 的字段和值(如:"Accept-Encoding: zip/zop;8bit")。 -i 执行 HEAD 请求,而不是 GET 。 -k 启用 KeepAlive 功能,即在一个 HTTP 会话中执行多个请求。默认不启用 KeepAlive 功能。 -n requests 在测试会话中所执行的请求个数。默认仅执行一个请求,此时其结果不具有意义。 -p POST-file 包含了 POST 数据的文件。 -P proxy-auth-username:password 对一个中转代理提供基本认证信息。用户名和密码由一个":"隔开,并将被以 base64 编码形式 发送。无论服务器是否需要(即是否发送了 407 代理认证需求代码),此字符串都会被发送。 -q 如果处理的请求数大于 150,ab 每处理大约 10%或者 100 个请求时,会在 stderr 输出一个进 度计数。此 -q 标记可以屏蔽这些信息。 -s 用于编译中(ab -h 会告诉你)使用了 SSL 的受保护的 https ,而不是 http 协议的时候。此功 能是实验性的,最好不要用。 -S 不显示中值和标准偏差值,而且在均值和中值为标准偏差值的 1 到 2 倍时,也不显示警告或出 错信息。默认时,会显示最小值/均值/最大值等数值。(为以前的版本提供支持) -t timelimit 测试所进行的最大秒数。内部隐含值是"-n 50000"。它可以使对服务器的测试限制在一个固定 的总时间以内。默认时,没有时间限制。 -T content-type

POST 数据时所使用的"Content-type"头信息。 -v verbosity 设置显示信息的详细程度,4 或更大值会显示头信息,3 或更大值可以显示响应代码(404,200 等),2 或更大值可以显示警告和其他信息。 -V 显示版本号并退出。 -w 以 HTML 表格形式输出结果。默认时,它是白色背景的两列宽度的一张表。 -x <table>-attributes 设置<table>属性的字符串。此属性被填入<table 这里 > 。 -X proxy[:port] 对请求使用代理服务器。 -y <tr>-attributes 设置<tr>属性的字符串。 -z <td>-attributes 设置<td>属性的字符串。 Bugs 程序中有各种静态声明的固定长度的缓冲区。另外,对命令行参数、服务器的响应头和其他外部输入的解 析也很简单,这可能会有不良后果。 没有完整实现 HTTP/1.x ;仅接受某些"预想"的响应格式。strstr()的频繁使用可能会带来性能问题,即 你可能是在测试 ab 而不是服务器的性能。

ab
apache 自带压力测试工具 windows 下使用(-c 不大于 100)
ab 的全称是 ApacheBench,是 Apache 附带的一个小工具,专门用于 HTTP Server 的 benchmark testing, 可以同时模拟多个并发请求。前段时间看到公司的开发人员也在用它作一些测试,看起来也不错,很简单, 也很容易使用,所以今天花一点时间看 了一下。 通过下面的一个简单的例子和注释,相信大家可以更容易理解这个工具的使用。 一个简单的例子 /* 在这个例子的一开始,我执行了这样一个命令 ab -n 10 -c 10 http://www.google.com/(不要忘了最后一个 '/')。这个命令的意思是启动 ab ,向 www.google.com 发送 10 个请求(-n 10) ,并每次发送 10 个请求(-c 10)——也就是说一次都发过去了。跟着下面的是 ab 输出的测试报告。*/ C:/wamp/bin/apache/Apache2.2.11/bin>ab -n 10 -c 10 http://www.google.com 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 1997-2005 The Apache Software Foundation, http://www.apache.org/ Benchmarking www.google.com (be patient).....done Server Software: Server Hostname: Server Port: Document Path: Document Length: Concurrency Level: 80 / 230 bytes 10 GWS/2.1 www.google.com

/*整个测试持续的时间*/ Time taken for tests: /*完成的请求数量*/ Complete requests: /*失败的请求数量*/ Failed requests: Write errors: Non-2xx responses: Keep-Alive requests: Total transferred: HTML transferred: Requests per second: 均值*/ Time per request: Time per request: Transfer rate: 3234.651 [ms] (mean) 323.465 [ms] (mean, across all concurrent requests) 1.55 [Kbytes/sec] received /*这个还不知道是什么意思,有知道的朋友请留言,谢谢 ^_^ */ /* 平均每秒网络上的流量,可以帮助排除是否存在网络流量过大导致响应时间延长的问题*/ /*网络上消耗的时间的分解,各项数据的具体算法还不是很清楚*/ Connection Times (ms) min mean[+/-sd] median Connect: Processing: Waiting: Total: 20 318 926.1 40 2160 1462.0 40 2160 1462.0 60 2479 1276.4 max 30 3034 3064 2954 3154 3154 3184 3034 0 0 10 10 6020 bytes 2300 bytes 3.09 [#/sec] (mean) 10 3.234651 seconds

/*整个场景中的网络传输量*/ /*整个场景中的 HTML 内容传输量*/ /*大家最关心的指标之一,相当于 LR 中的 每秒事务数 ,后面括号中的 mean 表示这是一个平均值*/ /*大家最 关心的指标之二,相当于 LR 中的 平均事务响应时间 ,后面括号中的 mean 表示这是一个平

/*下面的内容为整个场景中所有请求的响应情况。在场景中每个请求都有一个 响应时间,其中 50% 的用 户响应时间小于 3064 毫秒,60 % 的用户响应时间小于 3094 毫秒,最大的响应时间小于 3184 毫秒*/ Percentage of the requests served within a certain time (ms) 50% 3064

66% 3094 75% 3124 80% 3154 90% 3184 95% 3184 98% 3184 99% 3184 100% 3184 (longest request) 更 多信息 ab 不像 LR 那么强大,但是它足够轻便,如果只是在开发过程中想检查一下某个模块的响应情况,或者 做一些场景比较简单的测试,ab 还是一个不错的选择——至少不用花费很多时间去学习 LR 那些复杂的 功能,就更别说那 License 的价格了。 ab 是 Apache 超文本传输协议(HTTP)的性能测试工具。 其设计意图是描绘当前所安装的 Apache 的执行性 能, 主要是显示你安装的 Apache 每秒可以处理多少个请求。 选项 -A auth-username:password 对 服务器提供 BASIC 认证信任。 用户名和密码由一个:隔开,并以 base64 编码形式发送。 无论服务器是 否需要(即, 是否发送了 401 认证需求代码),此字符串都会被发送。 -c concurrency 一次产生的请求个数。默认是一次一个。 -C cookie-name=value 对请求附加一个 Cookie:行。 其典型形式是 name=value 的一个参数对。 此参数可以重复。 -d 不 显示"percentage served within XX [ms] table"的消息(为以前的版本提供支持)。 -e csv-file 产生一个以逗号分隔的(CSV)文件, 其中包含了处理每个相应百分比的请求所需要(从 1%到 100%)的相应 百分比的(以微妙为单位)时间。 由于这种格式已经“二进制化”,所以比'gnuplot'格式更有用。 -g gnuplot-file 把所有测试结果写入一个 'gnuplot'或者 TSV (以 Tab 分隔的)文件。 此文件可以方便地导入到 Gnuplot, IDL, Mathematica, Igor 甚至 Excel 中。 其中的第一行为标题。 -h 显示使用方法。 -H custom-header 对请求附加额外 的头信息。 此参数的典型形式是一个有效的头信息行,其中包含了以冒号分隔的字段和 值的对 (如, "Accept-Encoding: zip/zop;8bit"). -i 执行 HEAD 请求,而不是 GET。 -k 启用 HTTP KeepAlive 功能,即, 在一个 HTTP 会话中执行多个请求。 默认时,不启用 KeepAlive 功能. -n requests

在测试会话中所执行的请求个数。 默认时,仅执行一个请求,但通常其结果不具有代表意义。 -p POST-file 包含了需要 POST 的数据的文件. -P proxy-auth-username:password 对一个中转代理提供 BASIC 认证信任。 用户名和密码由一个:隔开,并以 base64 编码形式发送。 无论服 务器是否需要(即, 是否发送了 401 认证需求代码),此字符串都会被发送。 -q 如 果处理的请求数大于 150, ab 每处理大约 10%或者 100 个请求时,会在 stderr 输出一个进度计数。 此 -q 标记可以抑制这些信息。 -s 用 于编译中(ab -h 会显示相关信息)使用了 SSL 的受保护的 https, 而不是 http 协议的时候。此功能是实验 性的,也是很简陋的。最好不要用。 -S 不 显示中值和标准背离值, 而且在均值和中值为标准背离值的 1 到 2 倍时, 也不显示警告或出错信息。 默 认时,会显示 最小值/均值/最大值等数值。(为以前的版本提供支持). -t timelimit 测试所进行的最大秒数。其内部隐含值是-n 50000。 它可以使对服务器的测试限制在一个固定的总时间以 内。默认时,没有时间限制。 -T content-type POST 数据 所使用的 Content-type 头信息。 -v verbosity 设置显示信息的详细程度 - 4 或更大值会显示头信息, 3 或更大值可以显示响应代码(404, 200 等), 2 或更 大值可以显示警告和其他信息。 -V 显示版本号并退出。 -w 以 HTML 表的格式输出结果。默认时,它是白色背景的两列宽度的一张表。 -x <table>-attributes 设 置<table>属性的字符串。 此属性被填入<table 这里 >. -X proxy[:port] 对请求 使用代理服务器。 -y <tr>-attributes 设置<tr>属性的字符串. -z <td>-attributes 设置<td>属性的字符串. 缺陷 程序中有各种静态声明的固定长 度的缓冲区。 另外,对命令行参数、服务器的响应头和其他外部输入的 解析也很简单,这可能会有不良后果。 它没有完整地实现 HTTP/1.x; 仅接受某些'预想'的响应格式。 strstr(3)的频繁使用可能会带来性能问题, 即, 你可能是在测试 ab 而不是服务器的性能。 相 关链接 ab 是 Apache 的一个安装组件, 所以需要下载 Apache 安装后才能使用, 可以访问 Apache 的项目主页来 下载 http://httpd.apache.org/download.cgi

ab 的更多信息可以参加 Apache 主页上的描述 http://httpd.apache.org/docs/2.0/programs/ab.html 以下是 ab 的使用帮助: Usage: ab [options] [http://]hostname[:port]/path Options are: -n requests -t timelimit -p postfile Number of requests to perform Seconds to max. wait for responses Size of TCP send/receive buffer, in bytes File containing data to POST. Remember also to set -T -c concurrency Number of multiple requests to make -b windowsize

-T content-type Content-type header for POSTing, eg. 'application/x-www-form-urlencoded' Default is 'text/plain' -v verbosity -w -i How much troubleshooting info to print Print out results in HTML tables 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 -H attribute -A attribute -P attribute -X proxy:port -V -k -d -S -g filename -e filename -r -h Add cookie, eg. 'Apache=1234. (repeatable) Add Arbitrary header line, eg. 'Accept-Encoding: gzip' Add Basic WWW Authentication, the attributes Add Basic Proxy Authentication, the attributes Proxyserver and port number to use

Inserted after all normal header lines. (repeatable) are a colon separated username and password. are a colon separated username and password. Print version number and exit Use HTTP KeepAlive feature Do not show percentiles served table. Do not show confidence estimators and warnings. Output collected data to gnuplot format file. Output CSV file with percentages served Display usage information (this message)

Don't exit on socket receive errors.

ab 网站压力测试命令 格式: ./ab [options] [http://]hostname[:port]/path -n 测试会话中所执行的请求个数,默认时,仅执行一个请求 -c 一次产生的请求个数。默认是一次一个 -t 测试所进行的最大秒数 -v 设置显示信息的详细程度 - 4 或更大值会显示头信息, 3 或更大值可以显示响应代码(404, 200 等), 2 或更大 值可以显示警告和其他信息。 -V 显示版本号并退出。 4 个比较长用的参数 若有其他需要 man 下吧 一般工作中我们只用-n 和 -c:

例:./ab -c 1000 -n 1000 http://127.0.0.1/index.php -n 1000 表示总请求数为 1000 -c 10 表示并发用户数为 10 http://127.0.0.1/index.php 表示这些请求的目标 url #/usr/local/xiaobai/apache2054/bin/ab -c 1000 -n 1000 http://127.0.0.1/index.html.zh-cn.gb2312 This is ApacheBench, Version 2.0.41-dev <$Revision: 1.121.2.12 $> apache-2.0 Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Copyright (c) 1998-2002 The Apache Software Foundation, http://www.apache.org/ Benchmarking 127.0.0.1 (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 Finished 1000 requests Server Software: 被测试 web 服务软件名称他来自于 http 响应数据的头信息 Server Hostname: 表示请求的 url 中的主机部分名称 Server Port: 测试 web 服务器软件的监听端口 Document Path: 请求的 url 根的绝对路径 Document Length: 表示 http 响应数据的正文长度 Concurrency Level: 并发的用户数 Time taken for tests: 表示所有这些请求被处理完成所花费的时间总和 Complete requests: 表示总请求书 Failed requests: 失败的请求总数 Write errors: Total transferred: 所有请求的响应数据长度总和 HTML transferred: 所有请求的响应数据中正文数据的总和,也就是减去了 Total transferred 中的 HTML 响应数据中头信息的长度

Requests per second:132.12 [#/sec] (mean) 重点:吞吐率,他等于 Complete requests / Time taken for tests(相当于 LR 中的 每秒事务数 ,后面括号中 的 mean 表示这是一个平均值) Time per request: 用户平均请求等待时间,他等于 Time taken for tests /(Complete requests / Concurrency Level) 【相当于 LR 中 的 平均事务响应时间】 Time per request: 9.289 [ms] (mean, across all concurrent requests) 服务器平均请求处理时间他等于 Time taken for tests / Complete requests (每个请求实际运行时间的平均值) Transfer rate: 请求在单位时间内从服务器获取数据的长度他等于 Total transferred / Time taken for tests 这个统计选项可以很好的说明服务器在处理能力达到极限时其出口带宽的需求量 Percentage of the requests served within a certain time (ms) 用于描述每个请求处理时间的分布情况,例如:50% 1 间是指:Time per request ) .......... 100% 10 如有错误之处多多指正谢谢 100%请求处理时间不超过 10 秒 50%请求处理时间不超过 1 秒 (这里所指的处理时

使用 apache benchmark(ab) 测试报错: apr_socket_recv: Connection timed out (110)
使用 ab( apache benchmark )测试的时候,使用如下命令: ab -n 15000 -c 200 http://localhost/abc/abc.php 执行操作一定条数,或连续执行该命令会出现如下问题: apr_socket_recv: Connection timed out (110) 网上有说是资源描述符的问题,用 ulimit -n 65536 解决,试过不行。 查看系统日志: dmesg 显示大量下面错误 nf_conntrack: table full, dropping packet. 通过 google 后,加入如下参数 // 需 conntrack 模块 vi /etc/sysctl.conf net.nf_conntrack_max = 655360 net.netfilter.nf_conntrack_tcp_timeout_established = 1200 sysctl -p /etc/sysctl.conf 修改后,重新启用 apache ab 进行测试,问题解决。

http://www.tceic.com/184l2l912h160h4k767lilk8.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值