压力测试工具

来源:互联网 发布:vegas for mac破解版 编辑:程序博客网 时间:2024/05/21 22:40

到http://www.acme.com/software/http_load/ 下载http_load ,安装也很简单直接make;make instlall 就行。

http_load 的标准的两个例子是: 

  1. http_load -parallel 5 -fetches 1000 urls.txt  
  2. http_load -rate 2 -seconds 300 urls.txt  

 

例子只是个参考,参数其实可以自由组合,参数之间的选择并没有什么限制。比如你写成http_load -parallel 5 -seconds 300 urls.txt 也 是可以的。我们把参数给大家简单说明一下。 -parallel 简写 -p  含义是并发的用 户进程数。 

-fetches 简写 -f  含义是总计的访 问次数 

-rate    简写 -p  含义是每秒的访 问频率

-seconds 简写 -s  含义是总计的访问 时间


urls.txt 是一个url 列表,每个url 单独的一行。当然也可以直接跟一个url 而不是url 列表文件。
实例:
  1. http_load -rate 5 -seconds 10 urls  
  2. 49 fetches, 2 max parallel, 289884 bytes, in 10.0148 seconds  
  3. 5916 mean bytes/connection  
  4. 4.89274 fetches/sec, 28945.5 bytes/sec  
  5. msecs/connect: 28.8932 mean, 44.243 max, 24.488 min  
  6. msecs/first-response: 63.5362 mean, 81.624 max, 57.803 min  
  7. HTTP response codes:  
  8.   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
他们分别对应的常用性能指标参数Qpt-每秒响应用户数和response time,每连接响应用户时间。测试的结果主要也是看这两个值。当然仅有这两个指标并不能完成对性能的分析,我们还需要对服务器的cpu、men进行分 析,才能得出结论 

 

Sample run:

% ./http_load -rate 5 -seconds 10 urls49 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 -- 494.89274 fetches/sec 这个值得就是说服务器每秒能够响应的查询次数为4.8左右这个值得是根据 49 fetches / 10.0148 seconds 秒计算出来的

测试网站每秒所能承受的平均访问量

http_load -parallel 5 -fetches 1000 urls.txt

这段命令行是同时使用5个进程,随机访问urls.txt中的网址列表,总共访问1000次。运行之后的结果:

1000 fetches, 5 max parallel, 6e+06 bytes, in 58.1026 seconds
6000 mean bytes/connection
17.2109 fetches/sec , 103266 bytes/sec
msecs/connect: 0.403263 mean, 68.603 max, 0.194 min
msecs/first-response: 284.133 mean, 5410.13 max, 55.735 min
HTTP response codes:
code 200 — 1000

从上面的运行结果来看,目标网站仅仅能够承受每秒17次访问,不够强壮。

 

测试网站是否能承受住预期的访问压力

http_load -rate 2 -seconds 300 urls.txt

在300秒内保持一定的频率访问目标url。


如 果你需要测试https,你必须将 Makefile中
# CONFIGURE: If you want to compile in support for https, uncomment these
# definitions.  You will need to have already built OpenSSL, available at
# http://www.openssl.org/  Make sure the SSL_TREE definition points to the
# tree with your OpenSSL installation - depending on how you installed it,
# it may be in /usr/local instead of /usr/local/ssl.
SSL_TREE =    /usr 
SSL_DEFS =    -DUSE_SSL
SSL_INC =    -I$(SSL_TREE)/include
SSL_LIBS =    -L$(SSL_TREE)/lib -lssl -lcrypto

由于使用到openssl,你必须安装openssl和相应的开发环境

apt-get install openssl
apt-get install libssl-dev

find -name ssl.h
/usr /include/openssl/ssl.h

所 以上面红色字体部分必须修改

http_load常见问题

 

平常使用http_load过程中的一些总结,分享出来,大家可以一起补充;

1.提示:bytes count wrong
如果httpd_load获取到的页面数据和上次不一致则会报错byte count wrong
如果是动态页面,此报错可以忽略;

2.报错:too many open files
系统限制的open files太小,ulimit -n 修改open files值即可;

3.无法发送大请求 (请求长度>600个字符)
默认接受请求的buf大小 http_load.c

912 static void
913 handle_connect( int cnum, struct timeval* nowP, int double_check )
914 {
915 int url_num;
916 char buf[600]; //根据需要修改,如:char buf[4096]
917 int bytes, r;

重新编译即可得到可发送大请求

4.Cannot assign requested address
客户端频繁的连服务器,由于每次连接都在很短的时间内结束,导致很多的TIME_WAIT,以至于用光了可用的端口号,所以新的连接没办法绑定端口,所以 要改客户端机器的配置,
在sysctl.conf里加:

net.ipv4.tcp_tw_reuse = 1 表示开启重用。允许将TIME-WAIT sockets重新用于新的TCP连接,默认为0,表示关闭;
net.ipv4.tcp_timestamps=1 开启对于TCP时间戳的支持,若该项设置为0,则下面一项设置
不起作用
net.ipv4.tcp_tw_recycle=1 表示开启TCP连接中TIME-WAIT sockets的快速回收

 

 

 

apache ab压力测试


以前安装好APACHE总是不知道该如何测试APACHE的性能,现在总算找到一个测试工具了。就是APACHE自带的测试工具AB(apache benchmark).在APACHE的bin目录下。

格式: ./ab [options] [http://]hostname[:port]/path
参数:
    -n requests     Number of requests to perform
    //在测试会话中所执行的请求个数。默认时,仅执 行一个请求 
    -c concurrency Number of multiple requests to make
    //一次产生的请求个数。默认是一次一个。 
    -t timelimit    Seconds to max. wait for responses
    //测试所进行的最大秒数。其内部隐含值是-n 50000。它可以使对服务器的测试限制在一个固定的总时间以内。默认时,没有时间限制。
    -p postfile     File containing data to POST
    //包含了需要POST的数 据的文件. 
    -T content-type Content-type header for POSTing
    //POST数据所使用的Content-type头信息。 
    -v verbosity    How much troubleshooting info to print
    //设置显示信息的详细程度 - 4或更大值会显示头信息, 3或更大值可以显示响应代码(404, 200等), 2或更大值可以显示警告和其他信息。 -V 显示版本号并退出。
    -w              Print out results in HTML tables
    //以HTML表的格式输出结果。默认时,它是白色背景的两列宽度的一张表。
    -i              Use HEAD instead of GET
   // 执行HEAD请求,而不是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)
    //-C cookie-name=value 对请求附加一个Cookie:行。 其典型形式是name=value的一个参数对。此参数可以重复。 
    -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.
    //-P proxy-auth-username:password 对一个中转代理提供BASIC认证信任。用户名和密码由一个:隔开,并以base64编码形式发送。无论服务器是否需要(即, 是否发送了401认证需求代码),此字符串都会被发送。 
    -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)
    //-attributes 设置 属性的字符串. 缺陷程序中有各种静态声明的固定长度的缓冲区。另外,对命令行参数、服务器的响应头和其他外部输入的解析也很简单,这可能会有不良后果。它没有完整地实现 HTTP/1.x; 仅接受某些'预想'的响应格式。 strstr(3)的频繁使用可能会带来性能问题,即, 你可能是在测试ab而不是服务器的性能。

参数很多,一般我们用 -c 和 -n 参数就可以了. 例如:

./ab -c 1000 -n 1000 http://127.0.0.1/index.php

这个表示同时处理1000个请求并运行1000次index.php文件.
#/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:        Apache/2.0.54
// 平台apache 版本2.0.54
Server Hostname:        127.0.0.1
//服务器主机名
Server Port:            80
//服务器端口

Document Path:          /index.html.zh-cn.gb2312
//测试的页面文档 
Document Length:        1018 bytes
//文档大小

Concurrency Level:      1000
//并发数
Time taken for tests:   8.188731 seconds
//整个测试持续的时 间 
Complete requests:      1000
//完成的请 求数量 
Failed requests:        0
//失败的请求 数量 
Write errors:           0

Total transferred:      1361581 bytes
//整个场景中的网络传输量 
HTML transferred:       1055666 bytes
//整个场景中的HTML内容 传输量
Requests per second:    122.12 [#/sec] (mean)
//大家最关心的指标之一,相当于 LR 中的 每秒事务数 ,后面括号中的 mean 表示这是一个平均值 
Time per request:       8188.731 [ms] (mean)
//大家最关心的指标之二,相当于 LR 中的 平均事务响应时间 ,后面括号中的 mean 表示这是一个平均值 
Time per request:       8.189 [ms] (mean, across all concurrent requests)
//每个请求实际运行时间的平均值 
Transfer rate:          162.30 [Kbytes/sec] received
//平均每秒网络上的流量,可以帮助排除是否存在网络流量过大导致响应时间延长的问题

Connection Times (ms)
              min mean[+/-sd] median   max
Connect:        4 646 1078.7     89    3291
Processing:   165 992 493.1    938    4712
Waiting:      118 934 480.6    882    4554
Total:        813 1638 1338.9   1093    7785
//网络上消耗的时间的分解,各项数据的具体算法还不是很清楚

Percentage of the requests served within a certain time (ms)
50%   1093
66%   1247
75%   1373
80%   1493
90%   4061
95%   4398
98%   5608
99%   7368
100%   7785 (longest request)
//整个场景中所有请求的响应情况。在场景中每个请求都有一个响应时间,其中50%的用户响应时间小于1093 毫秒,60% 的用户响应时间小于1247 毫秒,最大的响应时间小于7785 毫秒

      由于对于并发请求,cpu实际上并不是同时处理的,而是按照每个请求获得的时间片逐个轮转处理的,所以基本上第一个Time per request时间约等于第二个Time per request时间乘以并发请求数

 

 

 

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 //每次传输所花最短时间



===========转自http://www.douban.com/group/topic/3703962/
说明 
ab的主要弱点在于它不能让你模拟一个更加真实的请求分布——例如你想通过设置一个请求的列表来在这些列表之间来回测试,而siege就可以。 

安装 

siege需要自己从http://www.joedog.org/上自己下载,然后编译: 

./configure --prefix=/usr/local/siege --mandir=/usr/local/man 
make 
# 转到超级用户 
make install 

注意在configure的时候,一定要设置mandir参数,否则当你通过 man siege 查看siege帮助的时候会看不到他的manual. 

安装完成后,运行bin中的siege_config命令来创建.siege文件 之后,你可以通过 

./siege -C 

命令来查看当前配置 

最简单的使用命令: 

./siege http://localhost/ 
#用来测试本地主页 

参数介绍 

* -cNUM 

设置并发的用户(连接)数量. 默认的连接数量可以到~/.siegerc中查看,指令为concurrent = x。比如-c10,设置并发10个连接 

* -rNUM 

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

* -tNUM 

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

* -b 

(benchmark),基准测试,如果设置这个参数的话,那么delay时间为0。man siege中有一句话这样说: 

it's not recommanded that you use this option while load testing. 

说明基准测试和load testing 是完全不同的,至于有什么不同,可以阅读BenchMarkingVSLoadTestingVSPerformance. 

* -f url.txt 

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

* 其他比较关注的测试方法,比如我想使用Keep-Alive方式进行测试,可以在.siegerc配置文件中进行修改,将connect = close改为 connect = keep-alive 

* 另外您还可以通过-H HEADER参数来设置请求header。

-===转自 

压力测试工具集合【ab,webbench,Siege,http_load,Web Application Stress】

http://zhengdl126.iteye.com/blog/437060

http://bbs.linuxtone.org/thread-62-1-1.html

 http://bbs.linuxtone.org/thread-62-1-1.html

 

 

loadrunner

ab

 

 

==================1.autobench结合httperf可以画出很漂亮的分析图
下载网址:http://www.xenoclast.org/autobench/ 
autobench --single_host --host1 www.test.com --uri1 /10K --quiet     \
          --low_rate 20 --high_rate 200 --rate_step 20 --num_call 10 \
          --num_conn 5000 --timeout 5 --file results.tsv

 

 


=============2.Siege 功能强大的压力测试软件
http://www.joedog.org/JoeDog/Siege 
操作手册:http://www.joedog.org/Siege/Manual 

-c 500   并发500个用户
-r 150      重复循环150次
-f sites.list     任务的URL列表

其它实用参数:

-i  随机 URL ,默认是从列表的上面到下面来打压力
-b 进行压力测试,不进行延时
-t  持续时间,即测试持续时间,在NUM时间后结束,单位默认为分


Siege 修正参数进行压力测试

./siege -c 500 -r 150 -f sites.list -i -b
复制代码



=====================3.webbench web/proxy测试软件,相当不错!


http://home.tiscali.cz:8080/~cz210552/webbench.html 
http://www.ibiblio.org/pub/Linux ... webbench-1.5.tar.gz

 

 


==================4.sysbench  数据库压力测试不错的软件,当你mysql调优以后不防有这个压压测试一下


http://sysbench.sourceforge.net/ 
sysbench是一个模块化的、跨平台、多线程基准测试工具,主要用于评估测试各种不同系统参数下的数据库负载情况。
       它主要包括以下几种方式的测试:
       1、cpu性能
       2、磁盘io性能
       3、调度程序性能
       4、内存分配及传输速度 
       5、POSIX线程性能
       6、数据库性能(OLTP基准测试)
       目前sysbench主要支持 MySQL,pgsql, oracle 这3种数据库。


----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
http://www.opensourcetesting.org/performance.php 

一、webbench
Web-bench is a simple web server benchark.
Web Bench is very simple tool for benchmarking WWW or proxy servers. Uses fork() for simulating multiple clients and can use HTTP/0.9-HTTP/1.1 requests.
This benchmark is not very realistic, but it can test if your HTTPD can realy handle that many clients at once (try to run some CGIs) without taking your machine down.
Displays pages/min and bytes/sec. Can be used in more aggressive mode with -f switch.
What's New in This Release:

# tar zxvf webbench-1.5.tar.gz
# cd webbench-1.5
# make && make install

#webbench -c 500 -t 30 
参数说明:-c表示并发数,-t表示时间(秒)

二、Siege:压力模拟/测试工具

最早使用的压力测试工具是apache的ab(apache benchmark),apache ab做重复压力测试不错,但是每次只能测试一个链接,如何测试一组链接(比如从日志中导出的1个小时的日志,做真实压力测试),后来找到了这个:
Siege是一个压力测试和评测工具,设计用于WEB开发这评估应用在压力下的承受能力:可以根据配置对一个WEB站点进行多用户的并发访问,记录每个用户所有请求过程的相应时间,并在一定数量的并发访问下重复进行。

SIEGE is an http regressive testing and benchmarking utility. It was designed to let web developers measure the performance of their code under duress, to see how it will stand up to load on the internet. It lets the user hit a webserver with a configurable number of concurrent simulated users. Those users place the webserver "under siege." The duration of the siege is measured in transactions, the sum of simulated users and the number of times each simulated user repeats the process of hitting the server. Thus 20 concurrent users 50 times is 1000 transactions, the length of the test.

下载/安装
Siege时一个开放源代码项目:http://www.joedog.org 

下载:
wget ftp://sid.joedog.org/pub/siege/siege-latest.tar.gz 

安装:
# ./configure
#make && make install

siege包含了一组压力测试工具:
SIEGE (1) Siege是一个HTTP压力测试和评测工具.
使用样例:
任务列表:www.chedong.com.url 文件
http://www.chedong.com/tech/ 
http://www.chedong.com/tech/acdsee.html 
http://www.chedong.com/tech/ant.html 
http://www.chedong.com/tech/apache_install.html 
http://www.chedong.com/tech/awstats.html 
http://www.chedong.com/tech/cache.html 
http://www.chedong.com/tech/click.html 
http://www.chedong.com/tech/cms.html 
http://www.chedong.com/tech/compress.html 
http://www.chedong.com/tech/cvs_card.html 
http://www.chedong.com/tech/default.html 
http://www.chedong.com/tech/dev.html 
http://www.chedong.com/tech/gnu.html 
....

# siege -c 20 -r 2 -f www.sina.com.cn 
参数说明:
-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 失败处理次数

注意:由于速度很快,可能会达不到并发速度很高就已经完成。Response time显示的是测试机器和被测试服务器之间网络链接状况。Transaction rate则表示服务器端任务处理的完成速度。

辅助工具:
增量压力测试:

为了方便增量压力测试,siege还包含了一些辅助工具:
bombardment (1)
是一个辅助工具:用于按照增量用户压力测试:
使用样例:
bombardment urlfile.txt 5 3 4 1
初始化URL列表:urlfile.txt
初始化为:5个用户
每次增加:3个用户
运行:4次
每个客户端之间的延迟为:1秒

输出成CSV格式:
siege2csv.pl (1)
siege2csv.pl将bombardment的输出变成CSV格式:
Time Data Transferred Response Time Transaction Rate Throughput Concurrency Code 200 (note that this is horribly broken.)
242 60.22 603064 0.02 4.02 10014.35 0.08
605 59.98 1507660 0.01 10.09 25136.05 0.12
938 59.98 2337496 0.02 15.64 38971.26 0.26
1157 60 2883244 0.04 19.28 48054.07 0.78


网络IO性能测试: http://bbs.linuxtone.org/thread-5437-1-1.html 
httpload: http://bbs.linuxtone.org/thread-2899-1-2.html 
             http://bbs.linuxtone.org/thread-1097-1-2.html

 

 

 

 

 

 

 

 

 

 

 

 

 

--------------------------------------------------1 Apache附带的工具ab

 

ab的全称是ApacheBench,是Apache附带的一个小工具,专门用于HTTP Server的benchmark testing,可以同时模拟多个并发请求。

在这个例子的一开始,我执行了这样一个命令ab -n 10 -c 10http://www.google.com/。这个命令的意思是启动ab,向www.google.com发送10个请求(-n 10) ,并每次发送10个请求(-c 10) ——也就是说一次都发过去了。

apache ab做重复压力测试不错,但是每次只能测试一个链接



D:\apahce\bin>ab.exe -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 2006 The Apache Software Foundation, http://www.apache.org/

Benchmarking www.google.com (be patient).....done


Server Software:        gws
Server Hostname:        www.google.com
Server Port:            80

Document Path:          /
Document Length:        4941 bytes 

Concurrency Level:      10
Time taken for tests:   5.218750 seconds//**整个测试持续的时间**
Complete requests:      10//**完成的请求数量**
Failed requests:        9//**失败的请求数量**
 
   (Connect: 0, Length: 9, Exceptions: 0)
Write errors:           0
Total transferred:      52730 bytes**整个场景中的网络传输量**
HTML transferred:       49540 bytes**整个场景中的HTML内容传输量**
Requests per second:    1.92 [#/sec] (mean) **大家最关心的指标之一,相当于LR中的每秒事务数,后面括号中的mean表示这是一个平均值**
Time per request:       5218.750 [ms] (mean) *大家最关心的指标之二,相当于LR中的平均事务响应时间,后面括号中的mean表示这是一个平均值**
 
Time per request:       521.875 [ms] (mean, across all concurrent requests)
Transfer rate:          9.77 [Kbytes/sec] received*平均每秒网络上的流量,可以帮助排除是否存在网络流量过大导致响应时间延长的问题** 

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:      187  488 257.6    437     921
Processing:   312 1673 1204.4   1547    3985
Waiting:      296 1668 1206.3   1546    3984
Total:        593 2162 1432.6   1890    4906
**下面的内容为整个场景中所有请求的响应情况。在场景中每个请求都有一个响应时间,其中50%的用户响应时间小于**毫秒,60%的用户响应时间小于**毫秒,最大的响应时间小于  **毫秒**
Percentage of the requests served within a certain time (ms)
  50%   1890
  66%   2406
  75%   3093
  80%   3984
  90%   4906
  95%   4906
  98%   4906
  99%   4906
 100%   4906 (longest request)

 

 

 

--------------------------------------------------------------------实际测试

Server Software:        Apache/2.2.3
Server Hostname:        www.netnov.cn
Server Port:            80

Document Path:          /
Document Length:        18958 bytes

Concurrency Level:      10 
Time taken for tests:   8.949 seconds 
Complete requests:      100 
Failed requests:        0
Write errors:           0
Total transferred:      1912100 bytes
HTML transferred:       1895800 bytes
Requests per second:    11.17 [#/sec] (mean)
Time per request:       894.906 [ms] (mean)
Time per request:       89.491 [ms] (mean, across all concurrent requests)
Transfer rate:          208.66 [Kbytes/sec] received
 

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:       78   87   8.9     94     109
Processing:   219  752 122.2    781     875
Waiting:      219  510 179.9    515     843
Total:        312  839 121.3    859     953

Percentage of the requests served within a certain time (ms)
  50%    859
  66%    859
  75%    875
  80%    890
  90%    921
  95%    937
  98%    953
  99%    953
 100%    953 (longest request)

-----------------------------------------------------------------------------

 

 


格式: ./ab [options] [http://]hostname[:port]/path
参数:
    -n requests     Number of requests to perform
    //在测试会话中所执行的请求个数。默认时,仅执行一个请求
    -c concurrency Number of multiple requests to make
    //一次产生的请求个数。默认是一次一个。 
    -t timelimit    Seconds to max. wait for responses
    //测试所进行的最大秒数。其内部隐含值是-n 50000。它可以使对服务器的测试限制在一个固定的总时间以内。默认时,没有时间限制。
    -p postfile     File containing data to POST
    //包含了需要POST的数据的文件. 
    -T content-type Content-type header for POSTing
    //POST数据所使用的Content-type头信息。
    -v verbosity    How much troubleshooting info to print
    //设置显示信息的详细程度 - 4或更大值会显示头信息, 3或更大值可以显示响应代码(404, 200等), 2或更大值可以显示警告和其他信息。 -V 显示版本号并退出。
    -w              Print out results in HTML tables
    //以HTML表的格式输出结果。默认时,它是白色背景的两列宽度的一张表。
    -i              Use HEAD instead of GET
   // 执行HEAD请求,而不是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)
    //-C cookie-name=value 对请求附加一个Cookie:行。 其典型形式是name=value的一个参数对。此参数可以重复。
    -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.
    //-P proxy-auth-username:password 对一个中转代理提供BASIC认证信任。用户名和密码由一个:隔开,并以base64编码形式发送。无论服务器是否需要(即, 是否发送了401认证需求代码),此字符串都会被发送。
    -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)

 

 

 

-------------------------------------------------2 webbench

wget http://blog.s135.com/soft/linux/webbench/webbench-1.5.tar.gz   
tar zxvf webbench-1.5.tar.gz   
cd webbench-1.5   
make && make install

#webbench -c 100 -t 10 http://192.168.200.100/info.php

参数说明:-c表示并发数,-t表示持续时间(秒)

 

 

root@ubuntu-desktop:/etc/nginx/sites-available# webbench -c 100 -t 10 http://192.168.200.100/info.php
Webbench - Simple Web Benchmark 1.5
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.

Benchmarking: GET http://192.168.200.100/info.php
100 clients, running 10 sec.

Speed=19032 pages/min, 18074373 bytes/sec.
Requests: 3172 susceed, 0 failed.

 

 

 

 

-----------------------------------------------------------3 Siege 

apache ab做重复压力测试不错,但是每次只能测试一个链接 

如何测试一组链接(比如从日志中导出的1个小时的日志,做真实压力测试),后来找到了这个:
Siege是一个压力测试和评测工具,设计用于WEB开发这评估应用在压力下的承受能力:可以根据配置对一个WEB站点进行多用户的并发访问,记录每个用户所有请求过程的相应时间,并在一定数量的并发访问下重复进行。 


下载/安装
Siege时一个开放源代码项目:http://www.joedog.org/siege/

下载:
wget ftp://sid.joedog.org/pub/siege/siege-latest.tar.gz

安装:
#./configure ; make
#make install

#siege -help (如果有help出现,则已经安装成功)

siege包含了一组压力测试工具:
SIEGE (1) Siege是一个HTTP压力测试和评测工具.
使用样例:
任务列表:www.chedong.com.url文件
http://www.chedong.com/tech/
http://www.chedong.com/tech/acdsee.html
http://www.chedong.com/tech/ant.html
http://www.chedong.com/tech/apache_install.html
http://www.chedong.com/tech/awstats.html
http://www.chedong.com/tech/cache.html
http://www.chedong.com/tech/click.html
http://www.chedong.com/tech/cms.html
http://www.chedong.com/tech/compress.html
http://www.chedong.com/tech/cvs_card.html
http://www.chedong.com/tech/default.html
http://www.chedong.com/tech/dev.html
http://www.chedong.com/tech/gnu.html
….


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 失败处理次数

 


辅助工具:
增量压力测试:
为了方便增量压力测试,siege还包含了一些辅助工具:
bombardment (1)
是一个辅助工具:用于按照增量用户压力测试:
使用样例:
bombardment urlfile.txt 5 3 4 1
初始化URL列表:urlfile.txt
初始化为:5个用户
每次增加:3个用户
运行:4次
每个客户端之间的延迟为:1秒

输出成CSV格式:
siege2csv.pl (1)
siege2csv.pl将bombardment的输出变成CSV格式:
Time Data Transferred Response Time Transaction Rate Throughput Concurrency Code 200 (note that this is horribly broken.)
242 60.22 603064 0.02 4.02 10014.35 0.08
605 59.98 1507660 0.01 10.09 25136.05 0.12
938 59.98 2337496 0.02 15.64 38971.26 0.26
1157 60 2883244 0.04 19.28 48054.07 0.78



----------------------------------------------------4 http_load

下载地址:http://www.acme.com/software/http_load/http_load-12mar2006.tar.gz

程序非常小,解压后也不到100K 居家旅行 携带方便 呵呵

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

命令格式:http_load   -p 并发访问进程数   -s 访问时间   需要访问的URL文件
例如:
引用
http_load -p 30 -s 60   urllist.txt

准 备URL文件:tst.list,文件格式是每行一个URL,URL最好超过50-100个测试效果比较好,另外,测试结果中主要的指标是 fetches/sec 这个选项,即服务器每秒能够响应的查询次数,用这个指标来衡量性能。似乎比 apache的ab准确率要高一些,也更有说服力一些。

官方的例子:
引用

% ./http_load -rate 10 -seconds 60 urllist.txt
49 fetches, 4 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



4.89274 fetches/sec 这个值得就是说服务器每秒能够响应的查询次数为4.8左右
这个值得是根据 49 fetches / 10.0148 seconds 秒计算出来的




------------------5 Web Application Stress 【附下载】
http://www.microsoft.com/downloads/details.aspx?FamilyID=e2c0585a-062a-439e-a67d-75a89aa36495&displaylang=en

 

说明:

1. 在“settings”的功能设置中,一个是Stress level (threads)这里是指定程序在后台用多少线程进行请求,也就是相当于模拟多少个客户机的连接,更加形象的就是说设置多少轰炸的线程数。一般填写 500~1000,因为这个线程数是根据本机的承受力来设置的,如果你对自己的机器配置有足够信心的话,那么设置的越高,轰炸的效果越好。

 

2.在“Test Run Time”中来指定一次压力测试需要持续的时间,分为天、小时、分、秒几个单位级别,你根据实际情况来设置吧!

 

 

使用:

在工具中点右键,选择Add命令,增加了一个新的测试项目:New script,对它进行设置,在主选项中的server中填写要测试的服务器的IP地址[192.168.200.100]。在下方选择测试的Web连接方式,这里的方式Verb选择 get,path选择要测试的Web页面路径[/info.php],

 

在“Settings”的功能设置中将Stress level (threads)线程数设置为1000。完毕后,点工具中的灰色三角按钮即可进行测试(如图4)。测试完毕,等待朋友把任务管理器以及连接查看的截图发过来!

 

攻 击开始后,朋友从任务管理器中可以看到CPU使用率已经达到100%,损耗率达到最大。在CMD窗口中使用命令netstat -an,可以看到我的IP地址在朋友服务器上的80端口进行了非常多的连接。而且它的Web网站已经打不开了,提示过多用户连接,达到了跟 D.O.S攻击一样的目的。

 

 

数据分析:
    选择“View”菜单下的“Reports”命令,或单击工具栏上的 按钮,打开报告窗口,在左侧列表中展开相应的报告。

检查Socket Errors部分是否有任何的socket有关的错误(值不为0)。

Socket Errors
--------------------------------------------------------------------------------
Connect:                      406
Send:                         0
Recv:                         306
Timeouts:                     0

这里列出每种socket错误的解释:Connect——客户端不能与服务器取得连接的次数。如果这个值偏高,检查在客户端与服务器之间产生的任何潜在的错误。从每个客户端Ping服务器或telnet服务器的端口80验证你得到正确的回应;Send——客户端不能正确发送数据到服务器的次数。如果这个值偏高,检查服务器是否正确地工作着。在客户端打开一个浏览器然后手工点击站点页面验证站点正确地工作着;Recv——客户端不能正确从服务器接收数据的次数。如果这个值偏高,执行和Send错误相同的操作,还要检查一下如果你减低负载系数,错误是否跟着减少;Timeouts——超时的线程的数目,而且随后就关闭了。如果这个值偏高,在客户端打开一个浏览器,然后手工点击站点页面验证是否即使只有一个用户你的程序也会很慢。再做一个不同负载系数的压力测试,看看程序的潜在特征。

 

Result Codes
Code      Description                   Count     
================================================================================
200       OK                            11058     
NA        HTTP result code not given    306      
    如果“socket”错误很低或为0,在左侧的报告列表中找到“Result Codes”部分。检查一下是否所有结果代码都是200,200表示所有请求都被服务器成功地返回。如果找到大于或等于400的结果,单击报告列表中的 “Page Data”节点,展开所有项目,查看每个脚本项在右边窗口页面数据的报告,找出出现错误的项目。


0 0