apache 自带的ab.exe 测试网站的并发量(网站压力测试)

AB(ApacheBench) 是 Apache 自带的超文本传输协议 (HTTP) 性能测试工具。 其设计意图是描绘当前所安装的 Apache 的执行性能, 主要是显示 Apache 每秒可以处理多少个请求。
该工具是 Apache 自带的工具。 安装了 Apache Http Server , 就有了 ab.exe 程序。
安装完后,在 apache 的 Bin 目录下有 ab.exe 程序。 这个就是我们的 AB 工具。
AB 工具的使用方法:(为方便使用,将ab.exe所在目录加入环境变量)

C:\Users\admin >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
-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
-r Don’t exit on socket receive errors.
-h Display usage information (this message)

示例:

C:\Users\admin >ab -n 1000 -c 10 http://www.dayima.com/

C:\Users\admin>ab -n 1000 -c 10 http://www.dayima.com/
This is ApacheBench, Version 2.3 <$Revision: 1748469 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking www.dayima.com (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/1.11.5
Server Hostname:        www.dayima.com
Server Port:            80

Document Path:          /
Document Length:        2364 bytes

Concurrency Level:      10
Time taken for tests:   145.818 seconds
Complete requests:      1000
Failed requests:        20
   (Connect: 0, Receive: 0, Length: 20, Exceptions: 0)
Non-2xx responses:      20
Total transferred:      3242246 bytes
HTML transferred:       2320180 bytes
Requests per second:    6.86 [#/sec] (mean)
Time per request:       1458.182 [ms] (mean)
Time per request:       145.818 [ms] (mean, across all concurrent requests)
Transfer rate:          21.71 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.4      0       1
Processing:     5 1451 215.8   1422    2482
Waiting:        3 1451 215.9   1422    2482
Total:          5 1451 215.8   1422    2483

Percentage of the requests served within a certain time (ms)
  50%   1422
  66%   1443
  75%   1462
  80%   1478
  90%   1666
  95%   1765
  98%   2058
  99%   2270
 100%   2483 (longest request)

C:\Users\admin>

使用ab,发送post数据:

apachebench网上的资料很多,但是甚至包括国外的文章以及官方文档出了help显示的内容之外就没有任何一丁点更详细些的内容了,要使用ab进行post数据测试.从help可以看出我们需要定义两个内容
一个是-p参数.指定需要post的数据,还有一个是-T参数,指定使用的content-type,我在服务器端简单的写了一个脚本.将获取到的post请求输出到文件.

<?php
echo $_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 ‘application/x-www-form-urlencoded’ http://192.168.0.2/test.php

使用get方式测试

ab -n 1 http://192.168.0.2/test.php?test=abc

猜你喜欢

转载自blog.csdn.net/zhezhebie/article/details/90340979
今日推荐