<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>OurApache &#187; ab</title>
	<atom:link href="http://ourapache.com/archives/tag/ab/feed" rel="self" type="application/rss+xml" />
	<link>http://ourapache.com</link>
	<description>我们致力于一个Apache知识的分享网站</description>
	<lastBuildDate>Tue, 13 Apr 2010 05:18:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>apache ab压力测试收藏</title>
		<link>http://ourapache.com/archives/168</link>
		<comments>http://ourapache.com/archives/168#comments</comments>
		<pubDate>Wed, 25 Feb 2009 10:14:32 +0000</pubDate>
		<dc:creator>OurApache</dc:creator>
				<category><![CDATA[Apache初级应用]]></category>
		<category><![CDATA[ab]]></category>
		<category><![CDATA[压力]]></category>

		<guid isPermaLink="false">http://www.ourapache.com/?p=168</guid>
		<description><![CDATA[以前安装好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 [...]]]></description>
			<content:encoded><![CDATA[<p>以前安装好APACHE总是不知道该如何测试APACHE的性能，现在总算找到一个测试工具了。就是APACHE自带的测试工具AB(apache benchmark).在APACHE的bin目录下。</p>
<p>格式： ./<a href="http://ourapache.com/archives/tag/ab" class="st_tag internal_tag" rel="tag" title="标签 ab 下的日志">ab</a> [options] [http://]hostname[:port]/path<br />
参数：<br />
    -n requests     Number of requests to perform<br />
    <span style="color: #ff0000;">//在测试会话中所执行的请求个数。默认时，仅执行一个请求</span><br />
    -c concurrency Number of multiple requests to make<br />
    <span style="color: #ff0000;">//一次产生的请求个数。默认是一次一个。 </span><br />
    -t timelimit    Seconds to max. wait for responses<br />
    <span style="color: #ff0000;">//测试所进行的最大秒数。其内部隐含值是-n 50000。它可以使对服务器的测试限制在一个固定的总时间以内。默认时，没有时间限制。<br />
</span>    -p postfile     File containing data to <a href="http://ourapache.com/archives/tag/post" class="st_tag internal_tag" rel="tag" title="标签 post 下的日志">POST</a><br />
    <span style="color: #ff0000;">//包含了需要POST的数据的文件. </span><br />
    -T content-type Content-type header for POSTing<br />
    <span style="color: #ff0000;">//POST数据所使用的Content-type头信息。</span><br />
    -v verbosity    How much troubleshooting info to print<br />
    <span style="color: #ff0000;">//设置显示信息的详细程度 &#8211; 4或更大值会显示头信息， 3或更大值可以显示响应代码(404, 200等), 2或更大值可以显示警告和其他信息。 -V 显示版本号并退出。<br />
</span>    -w              Print out results in HTML tables<br />
   <span style="color: #ff0000;"> //以HTML表的格式输出结果。默认时，它是白色背景的两列宽度的一张表。<br />
</span>    -i              Use HEAD instead of GET<br />
  <span style="color: #ff0000;"> // 执行HEAD请求，而不是GET。</span><br />
    -x attributes   String to insert as table attributes<br />
    //<br />
    -y attributes   String to insert as tr attributes<br />
    //<br />
    -z attributes   String to insert as td or th attributes<br />
    //<br />
    -C attribute    Add cookie, eg. &#8216;Apache=1234. (repeatable)<br />
    //<span style="color: #ff0000;">-C cookie-name=value 对请求附加一个Cookie:行。 其典型形式是name=value的一个参数对。此参数可以重复。</span><br />
    -H attribute    Add Arbitrary header line, eg. &#8216;Accept-Encoding: gzip&#8217;<br />
                    Inserted after all normal header lines. (repeatable)<br />
    -A attribute    Add Basic WWW Authentication, the attributes<br />
                    are a colon separated username and password.<br />
    -P attribute    Add Basic Proxy Authentication, the attributes<br />
                    are a colon separated username and password.<br />
    //<span style="color: #ff0000;">-P proxy-auth-username:password 对一个中转代理提供BASIC认证信任。用户名和密码由一个:隔开，并以base64编码形式发送。无论服务器是否需要(即, 是否发送了401认证需求代码)，此字符串都会被发送。</span><br />
    -X proxy:port   Proxyserver and port number to use<br />
    -V              Print version number and exit<br />
    -k              Use HTTP KeepAlive feature<br />
    -d              Do not show percentiles served table.<br />
    -S              Do not show confidence estimators and warnings.<br />
    -g filename     Output collected data to gnuplot format file.<br />
    -e filename     Output CSV file with percentages served<br />
    -h              Display usage information (this message)<br />
    //-attributes 设置 属性的字符串. 缺陷程序中有各种静态声明的固定长度的缓冲区。另外，对命令行参数、服务器的响应头和其他外部输入的解析也很简单，这可能会有不良后果。它没有完整地实现 HTTP/1.x; 仅接受某些&#8217;预想&#8217;的响应格式。 strstr(3)的频繁使用可能会带来性能问题，即, 你可能是在测试ab而不是服务器的性能。</p>
<p>参数很多,一般我们用 -c 和 -n 参数就可以了. 例如:</p>
<p>./ab -c 1000 -n 1000 <a href="http://127.0.0.1/index.php"><span style="color: #0000ff;">http://127.0.0.1/index.php</span></a></p>
<p>这个表示同时处理1000个请求并运行1000次index.php文件.<br />
#/usr/local/xiaobai/apache2054/bin/ab -c 1000 -n 1000 <a href="http://127.0.0.1/index.html.zh-cn.gb2312"><span style="color: #0000ff;">http://127.0.0.1/index.html.zh-cn.gb2312</span></a><br />
This is <a href="http://ourapache.com/archives/tag/apachebench" class="st_tag internal_tag" rel="tag" title="标签 apachebench 下的日志">ApacheBench</a>, Version 2.0.41-dev &lt;$Revision: 1.121.2.12 $&gt; apache-2.0<br />
Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, <a href="http://www.zeustech.net/"><span style="color: #0000ff;">http://www.zeustech.net/</span></a><br />
Copyright (c) 1998-2002 The Apache Software Foundation, <a href="http://www.apache.org/"><span style="color: #0000ff;">http://www.apache.org/</span></a></p>
<p>Benchmarking 127.0.0.1 (be patient)<br />
Completed 100 requests<br />
Completed 200 requests<br />
Completed 300 requests<br />
Completed 400 requests<br />
Completed 500 requests<br />
Completed 600 requests<br />
Completed 700 requests<br />
Completed 800 requests<br />
Completed 900 requests<br />
Finished 1000 requests<br />
Server Software:        Apache/2.0.54<br />
<span style="color: #ff0000;">//平台apache 版本2.0.54<br />
</span>Server Hostname:        127.0.0.1<br />
<span style="color: #ff0000;">//服务器主机名<br />
</span>Server Port:            80<br />
<span style="color: #ff0000;">//服务器端口</span></p>
<p>Document Path:          /index.html.zh-cn.gb2312<br />
<span style="color: #ff0000;">//测试的页面文档</span><br />
Document Length:        1018 bytes<br />
<span style="color: #ff0000;">//文档大小</span></p>
<p>Concurrency Level:      1000<br />
<span style="color: #ff0000;">//并发数<br />
</span>Time taken for tests:   8.188731 seconds<br />
<span style="color: #ff0000;">//整个测试持续的时间</span><br />
Complete requests:      1000<br />
<span style="color: #ff0000;">//完成的请求数量</span><br />
Failed requests:        0<br />
<span style="color: #ff0000;">//失败的请求数量</span><br />
Write errors:           0</p>
<p>Total transferred:      1361581 bytes<br />
<span style="color: #ff0000;">//整个场景中的网络传输量</span><br />
HTML transferred:       1055666 bytes<br />
<span style="color: #ff0000;">//整个场景中的HTML内容传输量<br />
</span>Requests per second:    122.12 [#/sec] (mean)<br />
<span style="color: #ff0000;">//<span style="color: red;">大家最关心的指标之一，相当于</span><span style="color: red;"> LR </span><span style="color: red;">中的</span><span style="color: red;"> </span><strong><span style="color: red;">每秒事务数</span></strong><span style="color: red;"> </span><span style="color: red;">，后面括号中的</span><span style="color: red;"> mean </span><span style="color: red;">表示这是一个平均值</span></span><br />
Time per request:       8188.731 [ms] (mean)<br />
<span style="color: #ff0000;">//<span style="color: red;">大家最关心的指标之二，相当于</span><span style="color: red;"> LR </span><span style="color: red;">中的</span><span style="color: red;"> </span><strong><span style="color: red;">平均事务响应时间</span></strong><span style="color: red;"> </span><span style="color: red;">，后面括号中的</span><span style="color: red;"> mean </span><span style="color: red;">表示这是一个平均值</span></span><br />
Time per request:       8.189 [ms] (mean, across all concurrent requests)<br />
<span style="color: #ff0000;">//每个请求实际运行时间的平均值</span><br />
Transfer rate:          162.30 [Kbytes/sec] received<br />
<span style="color: #ff0000;">//<span style="color: red;">平均每秒网络上的流量，可以帮助排除是否存在网络流量过大导致响应时间延长的问题</span></span></p>
<p>Connection Times (ms)<br />
              min mean[+/-sd] median   max<br />
Connect:        4 646 1078.7     89    3291<br />
Processing:   165 992 493.1    938    4712<br />
Waiting:      118 934 480.6    882    4554<br />
Total:        813 1638 1338.9   1093    7785<br />
<span style="color: #ff0000;">//<span style="color: red;">网络上消耗的时间的分解，各项数据的具体算法还不是很清楚</span></span></p>
<p>Percentage of the requests served within a certain time (ms)<br />
50%   1093<br />
66%   1247<br />
75%   1373<br />
80%   1493<br />
90%   4061<br />
95%   4398<br />
98%   5608<br />
99%   7368<br />
100%   7785 (longest request)</p>
<p><span style="color: #ff0000;">//整个场景中所有请求的响应情况。在场景中每个请求都有一个响应时间，其中50％的用户响应时间小于1093 毫秒，60％ 的用户响应时间小于1247 毫秒，最大的响应时间小于7785 毫秒</span></p>
<p><span style="color: #ff0000;">      由于对于并发请求，cpu实际上并不是同时处理的，而是按照每个请求获得的时间片逐个轮转处理的，所以基本上第一个Time per request时间约等于第二个Time per request时间乘以并发请求数</span></p>
<h3  class="related_post_title">相关文章</h3><ul class="related_post"><li>2008年12月29号 -- <a href="http://ourapache.com/archives/17" title="使用apachebench进行post压力测试">使用apachebench进行post压力测试</a></li></ul>
	标签：<a href="http://ourapache.com/archives/tag/ab" title="ab" rel="tag">ab</a>, <a href="http://ourapache.com/archives/category/primary" title="Apache初级应用" rel="tag">Apache初级应用</a>, <a href="http://ourapache.com/archives/tag/%e5%8e%8b%e5%8a%9b" title="压力" rel="tag">压力</a><br />
]]></content:encoded>
			<wfw:commentRss>http://ourapache.com/archives/168/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>使用apachebench进行post压力测试</title>
		<link>http://ourapache.com/archives/17</link>
		<comments>http://ourapache.com/archives/17#comments</comments>
		<pubDate>Mon, 29 Dec 2008 02:42:20 +0000</pubDate>
		<dc:creator>OurApache</dc:creator>
				<category><![CDATA[Apache初级应用]]></category>
		<category><![CDATA[ab]]></category>
		<category><![CDATA[apachebench]]></category>
		<category><![CDATA[post]]></category>
		<category><![CDATA[压力]]></category>
		<category><![CDATA[性能测试]]></category>

		<guid isPermaLink="false">http://www.ourapache.com/?p=17</guid>
		<description><![CDATA[apachebench网上的资料很多,但是甚至包括国外的文章以及官方文档,出了help显示的内容之外就没有任何一丁点更详细些的内容了]]></description>
			<content:encoded><![CDATA[<p>apachebench网上的资料很多<br />
但是甚至包括国外的文章以及官方文档<br />
出了help显示的内容之外就没有任何一丁点更详细些的内容了<br />
要使用ab进行post数据测试.从help可以看出我们需要定义两个内容<br />
一个是-p参数.指定需要post的数据<br />
还有一个是-T参数,指定使用的content-type<br />
我在服务器端简单的写了一个脚本.将获取到的post请求输出到文件</p>
<div class="hl-surround">
<div class="hl-main"><span style="color: blue;">&lt;?php</span><span style="color: gray;"><br />
</span><span style="color: green;">echo</span><span style="color: gray;"> </span><span style="color: #00008b;">$_REQUEST</span><span style="color: olive;">[</span><span style="color: #8b0000;">'</span><span style="color: red;">test</span><span style="color: #8b0000;">'</span><span style="color: olive;">]</span><span style="color: gray;">;<br />
</span><span style="color: #00008b;">$file</span><span style="color: gray;">=</span><span style="color: blue;">fopen</span><span style="color: olive;">(</span><span style="color: #8b0000;">&#8216;</span><span style="color: red;">/data/www/log.txt</span><span style="color: #8b0000;">&#8216;</span><span style="color: gray;">,</span><span style="color: #8b0000;">&#8216;</span><span style="color: red;">a+</span><span style="color: #8b0000;">&#8216;</span><span style="color: olive;">)</span><span style="color: gray;">;<br />
</span><span style="color: blue;">fwrite</span><span style="color: olive;">(</span><span style="color: #00008b;">$file</span><span style="color: gray;">,</span><span style="color: blue;">date</span><span style="color: olive;">(</span><span style="color: #8b0000;">“</span><span style="color: red;">Y-m-d H:i:s</span><span style="color: #8b0000;">“</span><span style="color: olive;">))</span><span style="color: gray;">;<br />
</span><span style="color: blue;">fwrite</span><span style="color: olive;">(</span><span style="color: #00008b;">$file</span><span style="color: gray;">,</span><span style="color: #00008b;">$_REQUEST</span><span style="color: olive;">[</span><span style="color: #8b0000;">'</span><span style="color: red;">test</span><span style="color: #8b0000;">'</span><span style="color: olive;">])</span><span style="color: gray;">;<br />
</span><span style="color: blue;">fclose</span><span style="color: olive;">(</span><span style="color: #00008b;">$file</span><span style="color: olive;">)</span><span style="color: gray;">;<br />
</span><span style="color: blue;">?&gt;</span></div>
</div>
<p>然后在本地生成post.txt文件<br />
内容为test=abc<br />
使用ab进行测试<br />
<a href="http://ourapache.com/archives/tag/ab" class="st_tag internal_tag" rel="tag" title="标签 ab 下的日志">ab</a> -n 1 -p <a href="http://ourapache.com/archives/tag/post" class="st_tag internal_tag" rel="tag" title="标签 post 下的日志">post</a>.txt http://192.168.0.2/test.php<br />
发现服务器端接受到了请求,但是没有受到post的数据<br />
使用类型之后.也还是不行<br />
ab -n 1 -p post.txt -T ‘text/html’ http://192.168.0.2/test.php<br />
使用get方式测试<br />
ab -n 1 http://192.168.0.2/test.php?test=abc<br />
服务器端则可以正常工作<br />
和开始说的一样.翻烂了google也没有找到<br />
最后只能用wireshark抓包<br />
最后发现content-type一定要设置成为<br />
application/x-www-form-urlencoded<br />
最后如下测试.才最后通过<br />
ab -n 1 -p post.txt -T ‘application/x-www-form-urlencoded’ http://192.168.0.2/test.php<br />
还有postfile<br />
如果有多条记录<br />
内容可以写成</p>
<div class="hl-surround">
<div class="hl-main">test1=a&amp;test2=b</div>
</div>
<p>类似这样即可<br />
这个也是文档中没有提及的,让我一开始以为postfile的格式有误.<br />
网上有提到过一种格式</p>
<div class="hl-surround">
<div class="hl-main">test1=a<br />
test2=b</div>
</div>
<p>这种是不对的<br />
这样的ab会把整个</p>
<div class="hl-surround">
<div class="hl-main">a回车test2=b</div>
</div>
<p>当作test1这个field传送出去</p>
<h3  class="related_post_title">相关文章</h3><ul class="related_post"><li>2009年02月25号 -- <a href="http://ourapache.com/archives/168" title="apache ab压力测试收藏">apache ab压力测试收藏</a></li></ul>
	标签：<a href="http://ourapache.com/archives/tag/ab" title="ab" rel="tag">ab</a>, <a href="http://ourapache.com/archives/tag/apachebench" title="apachebench" rel="tag">apachebench</a>, <a href="http://ourapache.com/archives/category/primary" title="Apache初级应用" rel="tag">Apache初级应用</a>, <a href="http://ourapache.com/archives/tag/post" title="post" rel="tag">post</a>, <a href="http://ourapache.com/archives/tag/%e5%8e%8b%e5%8a%9b" title="压力" rel="tag">压力</a>, <a href="http://ourapache.com/archives/tag/%e6%80%a7%e8%83%bd%e6%b5%8b%e8%af%95" title="性能测试" rel="tag">性能测试</a><br />
]]></content:encoded>
			<wfw:commentRss>http://ourapache.com/archives/17/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

