近期在做 压力測试工具,除了apache的ab測试工具外,发现webbentch工具也不错,这里简介下这两个工具。
一、webbentch安装:
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
假设没有安装ctags。则安装的时候会报错。ctags的安装:
apt-get install ctags
或者依照以下的步骤进行手动安装:
wget http://prdownloads.sourceforge.net/ctags/ctags-5.8.tar.gz
tar zxvf ctags-5.8.tar.gz
cd ctags-5.8
./configure
make && make install
二、webbentch使用:
測试原理:指定client的并发数和运行时间。查看server发出的请求中susceed的个数和failed的个数
使用命令:webbentch -c 10000 -t 60 http://xx.xx.xx.156:8082/index.html
-c: 发起请求的client数,也就是我们所说的并发数
-t:运行时间长度
运行结果例如以下:
Webbench - Simple Web Benchmark 1.5
Requests: 1033020 susceed, 5 failed.
Copyright (c) Radim Kolar 1997-2004, GPL Open Source Software.
Benchmarking: GET http://10.103.13.156:8082/index.html
10000 clients, running 60 sec.
Speed=1033025 pages/min, 3856600 bytes/sec.
Requests: 1033020 susceed, 5 failed.
三、apache的ab使用:
測试原理:指定client的并发数和请求总量。计算server每秒能够处理的请求数和每一个请求响应的时间
使用命令:ab -c 10000 -n 80000 http://xx.xx.xx.156:8082/index.html
-c : 发起请求的client数。也就是我们所说的并发数
-n:发起的总请求数
运行结果例如以下:
须要关心的几个參数:Requests per second、Time per request
This is ApacheBench, Version 2.3 <$Revision: 1528965 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking 10.103.13.156 (be patient) Completed 8000 requests Completed 16000 requests Completed 24000 requests Completed 32000 requests Completed 40000 requests Completed 48000 requests Completed 56000 requests Completed 64000 requests Completed 72000 requests Completed 80000 requests Finished 80000 requests Server Software: nginx //webserver Server Hostname: xx.xx.xx.156 //webserver地址 Server Port: 8082 //webserverport Document Path: /index.html //请求地址 Document Length: 2 bytes //返回的数据长度 Concurrency Level: 10000 //设置的并发数,就是-c设置的值 Time taken for tests: 13.691 seconds //全部请求运行完毕所耗费的时间 Complete requests: 80000 //完毕的请求数 Failed requests: 0 //失败的请求数 Total transferred: 17920000 bytes //传递数据的大小,包含header的信息 HTML transferred: 160000 bytes //传递的html的大小。这里的数字等于 (Document Length) * (Complete requests) Requests per second: 5843.27 [#/sec] (mean) //美妙的请求数,也就是我们server能够承受的实际并发数,即通常所受的rps Time per request: 1711.371 [ms] (mean) //每一个请求的响应时间,mean表示是平均值 Time per request: 0.171 [ms] (mean, across all concurrent requests) //每一个请求的时间。等于 (Time taken for tests * 1000ms) / Complete requests Transfer rate: 1278.22 [Kbytes/sec] received //每秒传输的数据量。能够计算是否是带宽的影响 Connection Times (ms) //时间的统计 min mean[+/-sd] median max Connect: 2 156 486.3 18 4700 Processing: 12 240 920.8 19 12024 Waiting: 12 240 920.8 18 12024 Total: 29 396 1098.9 37 13050 Percentage of the requests served within a certain time (ms) 50% 37 //37毫秒响应了37%的请求 66% 45 //45毫秒响应了66%的请求 75% 143 //143毫秒响应了75%的请求,以下的以此类推 80% 258 90% 1035 95% 3034 98% 3702 99% 6029 100% 13050 (longest request) |
三、注意事项:
在使用webbentch和apache的ab进行压力測试的时候,假设測试的url地址中有多个參数,须要对url中的"&"符号进行转义,输入“\&”就可以;把"&"=>"%26"是没有效果的。
如url为 http://xx.xx.xx.156:8080/info.php?
p1=v1&p2=v2&p3=v3
转换后 http://xx.xx.xx.156:8080/info.php?p1=v1\&p2=v2\&p3=v3