如何使用Apache的ab工具进行网站apache 性能测试试

apache 自带的ab.exe 测试网站的并发量(网站压力测试) - 经验小记 - ITeye技术网站
博客分类:
AB(ApacheBench) 是 Apache 自带的超文本传输协议 (HTTP) 性能测试工具。 其设计意图是描绘当前所安装的 Apache 的执行性能, 主要是显示 Apache 每秒可以处理多少个请求。
该工具是 Apache 自带的工具。 安装了 Apache Http Server , 就有了 ab.exe 程序。
安装完后,在 apache 的 Bin 目录下有 ab.exe 程序。 这个就是我们的 AB 工具。
AB 工具的使用方法:
C: &cd C:\Program Files (x86)\Apache Software Foundation\Apache2.2\bin
C:\Program Files (x86)\Apache Software Foundation\Apache2.2\bin&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
-b windowsize
Size of TCP send/receive buffer, in bytes
-p postfile
File containing data to POST. Remember also to set -T
-u putfile
File containing data to PUT. Remember also to set -T
-T content-type Content-type header for POSTing, eg.
'application/x-www-form-urlencoded'
Default is 'text/plain'
-v verbosity
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
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
Print version number and exit
Use HTTP KeepAlive feature
Do not show percentiles served table.
Do not show confidence estimators and warnings.
-g filename
Output collected data to gnuplot format file.
-e filename
Output CSV file with percentages served
Don't exit on socket receive errors.
Display usage information (this message)
C:\Program Files (x86)\Apache Software Foundation\Apache2.2\bin&
C:\Program Files (x86)\Apache Software Foundation\Apache2.2\bin&ab -n 1000 -c 50 http://blog.csdn.net/tianlesoftware/archive//5622268.aspx
-- 注意, 这里要写一个具体的页面
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 blog.csdn.net (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/0.7.65
Server Hostname:
blog.csdn.net
Server Port:
Document Path:
/tianlesoftware/archive//5622268.aspx -- 请求资源
Document Length:
-- 文档返回的长度,不包括相应头
Concurrency Level:
-- 并发个数
Time taken for tests:
118.549 seconds
-- 请求消耗总时间
Complete requests:
-- 总请求数
Failed requests:
(Connect: 1, Receive: 0, Length: 0, Exceptions: 0)
Write errors:
Non-2xx responses:
Total transferred:
334000 bytes
HTML transferred:
169000 bytes
Requests per second:
8.44 [#/sec] (mean)
-- 平均每秒请求数
Time per request:
[ms] (mean)
-- 平均每个请求时间
Time per request:
118.549 [ms] (mean, across all concurrent requests)
-- 平均每个请求时间除以并发数, 这里是
Transfer rate:
2.75 [Kbytes/sec] received
-- 时间传输速率
Connection Times (ms)
mean[+/-sd] median
Processing:
Percentage of the requests served within a certain time (ms)
25435 (longest request)
C:\Program Files (x86)\Apache Software Foundation\Apache2.2\bin&
同时处理 50 个并发请求并运行 1000 次 :
/tianlesoftware/archive//5622268.aspx
在并发 50 个请求的情况下,完成 1000 次的访问请求,共花了 118.549 秒,这个程序每秒可处理 8.44 个请求。
1,使用ab,发送post数据:
apachebench网上的资料很多但是甚至包括国外的文章以及官方文档出了help显示的内容之外就没有任何一丁点更详细些的内容了要使用ab进行post数据测试.从help可以看出我们需要定义两个内容一个是-p参数.指定需要post的数据还有一个是-T参数,指定使用的content-type我在服务器端简单的写了一个脚本.将获取到的post请求输出到文件
&?phpecho $_REQUEST['test'];$file=fopen('/data/www/log.txt','a+');fwrite($file,date("Y-m-d H:i:s"));fwrite($file,$_REQUEST['test']);fclose($file);?&
然后在本地生成post.txt文件内容为test=abc使用ab进行测试ab -n 1 -p post.txt http://192.168.0.2/test.php发现服务器端接受到了请求,但是没有受到post的数据使用类型之后.也还是不行ab -n 1 -p post.txt -T ‘text/html’ http://192.168.0.2/test.php使用get方式测试ab -n 1 http://192.168.0.2/test.php?test=abc服务器端则可以正常工作和开始说的一样.翻烂了google也没有找到最后只能用wireshark抓包最后发现content-type一定要设置成为application/x-www-form-urlencoded最后如下测试.才最后通过ab -n 1 -p post.txt -T ‘application/x-www-form-urlencoded’ http://192.168.0.2/test.php还有postfile如果有多条记录内容可以写成test1=a&test2=b类似这样即可这个也是文档中没有提及的,让我一开始以为postfile的格式有误.网上有提到过一种格式test1=atest2=b这种是不对的这样的ab会把整个 a回车test2=b当作test1这个field传送出去
2,使用ab发送get数据
直接将url地址,加双引号如果”"http://test.qq/?c=index&r=&sid=dShRB6zkP0twTOOwIim5“
下载次数: 77
浏览 13000
浏览: 40595 次
来自: 广州
直接忽悠人的S寒NO江W 的BLOG
用户名:S寒NO江W
文章数:30
访问量:3294
注册日期:
阅读量:5863
阅读量:12276
阅读量:417307
阅读量:1104909
51CTO推荐博文
Apache服务器的性能测试工具日志分析工具&站点的压力测试工具:简称&在安装软件包时就已经安装Ab的用法:先打开文件添加一条记录服务器的地址&与站点的映射Ab&&&-c&&一次并发请求的次数&&&&&&-n&&&总共请求的次数&&&&&&&服务器每秒所接受的请求数是测试服务器站点的重要指标,每秒接受的请求数越大,站点的性能就越好,一般在1000次左右属于正常,如果低于次,就要进行性能优化。&工具:版本&http_load-12mar2006.tar.tar源码安装先解压然后&&解压形成一个目录切换到这个目录下面&都是&文件和文件直接Make&install&时提示出错没有目录,所以在下创建目录然后再目录下创建目录再次&现在就会形成一个工具http_load切换到查看是否在环境变量里呢?如果在环境变量的目录里,就可以在任何时候执行这个程序Echo&&$PATHhttp_load&的用法&&&&Apache&的日志分析工具:下载网址&&webalizer&&&的特性&1&是语言编写的程序,所以具有很高的运行效率。2&&支持标准的一般日志文件格式(),除此之外,也支持几种组合日志格式()。3&可以支持多语言,也可以自己本地化工作。4&&支持命令行配置及配置文件。5&&支持多平台,比如说&Webalizer&的安装我们可以去官网上下载最新版本的源码&&也可以安装包版本是webalizer-2.01_10-30.1.i386.rpm&,版本比较低,这里我们就用rpm包&安装好之后&机会形成一些目录和文件在就是我们所需要的日志分析工具Webalizer&&&这种工具是把分析的结果形成一个文件,文件里有图片有表格等,并且这个文件可以以网页的形式打开。-t&&指明报告题目的主机名可以是网站的名称-F&日志格式类型有-p&&递增模式&,没分析一次后就会产生一个历史文件,这样下次在分析的时候,就可以不处理分析过的部分。-o&&指定存放分析结果内容的文件。-n&&&指定的服务器的主机名&。&我们是要使用这个工具分析日志,哪些日志啊?成功访问服务器的日志access_log&&访问服务器失败的日志。比如说要统计一个网站的成功的访问量,有多少人访问。隔多长时间一分析,一天&,一个小时,要解决隔多长时间一分析的问题,所以要创建一个工作任务。打开工作任务表创建工作任务目录&在任务目录中创建任务,这个任务实际上是一个脚本&,用于分析日志的脚本。&修改脚本的权限用户对它有执行的权限在站点主目录下创建目录用于存放任务执行形成的报告文件&查看计划任务的日志发现任务已经执行&切换到/var/www/html/log目录下形成网页格式的报告文件和一些图片通过浏览器打开&&&在这个网页中有直观形象的展示出日志的分析结果,报告题目的名称,形成报告文件的时间,日平均网站的访问量,访问的文件,访问的页数,数据流量的大小。还有每月网站的访问量,访问的文件,访问的页数,数据流量的大小。&&&&&&&&&&&&&&&&&本文出自 “” 博客,请务必保留此出处
了这篇文章
类别:┆阅读(0)┆评论(0)Apache自带的性能测试工具ab的使用
Apache自带的性能测试工具ab的使用
Apache自带的性能测试工具ab的使用
  小弟在学校负责一个测试团队,为学校的项目做测试,其间有些肤浅的作品,还请各位前辈多多指导^__^
  1 概述
  &&& ab(ApacheBench)是Apache自带的超文本传输协议(HTTP)性能测试工具。 其设计意图是描绘当前所安装的Apache的执行性能, 主要是显示你安装的Apache每秒可以处理多少个请求。
  2 使用
  2.1 安装
  Apache服务器套件自带ab,只要安装Apache即可,无需另行安装ab。ab位于%ApacheHome%/bin目录下(“%ApacheHome%”为Aapche安装路径),你也可以把ab.exe文件copy出来,独立使用。
  2.2 参数列表
  C:\&abab: wrong number of argumentsUsage: ab [options] //]hostname[:port]/pathOptions 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)
  * 中文的列表可以查看Apache手册中文版。
  &&& &&& 以上参数最常用的是-n 在测试会话中所执行的请求个数;和-c 一次同时产生的并发请求个数。
  2.3 实例
  假设我们要测试一个PHP论坛系统,其中一个性能测试用例是:“同时处理50个并发请求并运行 1000 次index.php 首页”,我们可以在cmd shell中输入 ab -n 1000 -c 50 ,运行结束后,ab会自动显示测试结果,如下:
  E:\Webser\Apache2\bin&ab -n 1000 -c 50 This is ApacheBench, Version 2.0.41-dev &$Revision: 1.121.2.12 $& apache-2.0Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, Copyright (c)
The Apache Software Foundation,
  Benchmarking 172.16.11.180 (be patient)Completed 100 requestsCompleted 200 requestsCompleted 300 requestsCompleted 400 requestsCompleted 500 requestsCompleted 600 requestsCompleted 700 requestsCompleted 800 requestsCompleted 900 requestsFinished 1000 requests
  Server Software:&&&& ApacheServer Hostname:&&&& 172.16.11.180Server Port:&&&&&&&& 88
  Document Path:&&&&&& /bbs/index.phpDocument Length:&&&& 36962 bytes
  Concurrency Level:&&&& 50Time taken for tests:&& 262.515625 secondsComplete requests:&&&& 1000Failed requests:&&&& 198& (Connect: 0, Length: 198, Exceptions: 0)Write errors:&&&&&& 0Total transferred:&&&&
bytesHTML transferred:&&&&
bytesRequests per second:&& 3.81 [#/sec] (mean)Time per request:&&&&
[ms] (mean)Time per request:&&&& 262.516 [ms] (mean, across all concurrent requests)Transfer rate:&&&&&& 139.16 [Kbytes/sec] received
  Connection Times (ms)&&&&&&& min mean[+/-sd] median&& maxConnect:&&&& 0&& 1&& 4.5&&&& 0&&&& 15Processing:&& 297 .6 12921&& 30578Waiting:&&&& 281 .6 12906&& 30562Total:&&&& 312 .5 12921&& 30578
  Percentage of the requests served within a certain time (ms)50% 1292166% 1320375% 1345380% 1354690% 1378195% 1415698% 1475099% 18328100% 30578 (longest request)
  &&& 以上结果指出,在并发50个请求的情况下,完成1000次的访问请求,共花了262.515秒,这个程序每秒可处理3.81个请求。
  &&& 2.4 问题
  在实际使用中,我发现-c 参数,即一次同时产生的并发请求个数最多设置成64,大于等于65就会报错,不知道为什么。
  3 资料
  ab官方网站:
  Apache&2.0手册中文版翻译项目ab部分:-cn/programs/l
&&&主编推荐
H3C认证Java认证Oracle认证
基础英语软考英语项目管理英语职场英语
.NETPowerBuilderWeb开发游戏开发Perl
二级模拟试题一级模拟试题一级考试经验四级考试资料
软件测试软件外包系统分析与建模敏捷开发
法律法规历年试题软考英语网络管理员系统架构设计师信息系统监理师
高级通信工程师考试大纲设备环境综合能力
路由技术网络存储无线网络网络设备
CPMP考试prince2认证项目范围管理项目配置管理项目管理案例项目经理项目干系人管理
职称考试题目
招生信息考研政治
网络安全安全设置工具使用手机安全
生物识别传感器物联网传输层物联网前沿技术物联网案例分析
Java核心技术J2ME教程
Linux系统管理Linux编程Linux安全AIX教程
Windows系统管理Windows教程Windows网络管理Windows故障
数据库开发Sybase数据库Informix数据库
&&&&&&&&&&&&&&&
希赛网 版权所有 & &&温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!&&|&&
LOFTER精选
网易考拉推荐
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
2、切换至你操作系统的apache目录的bin目录下
3、然后输入命令,下面以测试为例,进行一个简单的常用压力测试
输入命令"ab -c 100 -n 100 "然后回车,你会看到:
图片中参数含义讲解:
Concurrency Level---&整个测试持续的时间
Time taken&for&tests---&完成的请求数量
Complete requests---&失败的请求数量Keep-Alive requests---&保持联机连接的请求数量。只有在命令行中使用-k,才能看到该属性值Total transferred----&整个场景中的网络传输量HTML transferred----&整个场景中的HTML内容传输量Requests per second----&每秒钟平均处理的请求数Time per request----&每个线程下的一组请求平均消耗时间Time per request----&并发的每个请求平均消耗时间Transfer rate----&平均每秒网络上的流量,可以帮助排除是否存在网络流量过大导致响应时间延长的问题
Percentage of the requests served within a certain time (ms)
这句话的意思是:下面的内容为整个场景中所有请求的响应情况
而刚刚输入的:ab -c 100 -n 100 的意思是:请求100次,100个并发
懂了吗?各位.......有错欢迎纠错,觉得不错的话,就:
如果觉得文章不错,点一下周围的广告,谢谢!
阅读(8347)|
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
历史上的今天
loftPermalink:'',
id:'fks_',
blogTitle:'Apache自带压力测试工具AB的使用方法',
blogAbstract:'
&&&&&&& 昨天,答应了一个网友“ヾ习惯守护你”,今天写一个压力测试的工具使用方法的讲解给他,因为他过一阵子要对将上线的网站进行压力测试,那就不扯淡了,开始吧!
&&&&&&&& 记得上次写的是用webbench进行压力测试的,今天就讲Apache自带工具进行压力测试吧!先介绍一下基础知识.....
&&&&&&&& 什么是压力测试,为什么要进行压力测试?
&&&&&&&& 压力测试通过确定一个系统的瓶颈或者不能接收的性能点,来获得系统能提供的最大的服务级别的测试。通俗地讲,压力测试是为了发现在什么条件下您的应用程序的性能会变得不可接受。再简单点,就是你网站的性能的一个评定,性能由本身程序和网站服务器共同决定。 而进行压力测试,就是为了让你更好得掌握网站的各个信息。
blogTag:'',
blogUrl:'blog/static/',
isPublished:1,
istop:false,
modifyTime:9,
publishTime:8,
permalink:'blog/static/',
commentCount:1,
mainCommentCount:1,
recommendCount:5,
bsrk:-100,
publisherId:0,
recomBlogHome:false,
currentRecomBlog:false,
attachmentsFileIds:[],
groupInfo:{},
friendstatus:'none',
followstatus:'unFollow',
pubSucc:'',
visitorProvince:'',
visitorCity:'',
visitorNewUser:false,
postAddInfo:{},
mset:'000',
remindgoodnightblog:false,
isBlackVisitor:false,
isShowYodaoAd:true,
hostIntro:'',
hmcon:'1',
selfRecomBlogCount:'0',
lofter_single:''
{list a as x}
{if x.moveFrom=='wap'}
{elseif x.moveFrom=='iphone'}
{elseif x.moveFrom=='android'}
{elseif x.moveFrom=='mobile'}
${a.selfIntro|escape}{if great260}${suplement}{/if}
{list a as x}
推荐过这篇日志的人:
{list a as x}
{if !!b&&b.length>0}
他们还推荐了:
{list b as y}
转载记录:
{list d as x}
{list a as x}
{list a as x}
{list a as x}
{list a as x}
{if x_index>4}{break}{/if}
${fn2(x.publishTime,'yyyy-MM-dd HH:mm:ss')}
{list a as x}
{if !!(blogDetail.preBlogPermalink)}
{if !!(blogDetail.nextBlogPermalink)}
{list a as x}
{if defined('newslist')&&newslist.length>0}
{list newslist as x}
{if x_index>7}{break}{/if}
{list a as x}
{var first_option =}
{list x.voteDetailList as voteToOption}
{if voteToOption==1}
{if first_option==false},{/if}&&“${b[voteToOption_index]}”&&
{if (x.role!="-1") },“我是${c[x.role]}”&&{/if}
&&&&&&&&${fn1(x.voteTime)}
{if x.userName==''}{/if}
网易公司版权所有&&
{list x.l as y}
{if defined('wl')}
{list wl as x}{/list}}

我要回帖

更多关于 apache性能测试工具ab 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信