压力测试工具-ApacheAB

Apache AB 模拟并发请求,测试服务器在并发请求下的运行效率

1. 压力测试Apache AB

1.1. 下载Apache HTTP Server

http://httpd.apache.org/download.cgi

打开终端,进入到刚刚解压完的http server目录

执行 ./configure (根据官方文档说明,不加prefix会有默认的路径)

可能你会见到如下错误,找不到APR

1.2. 安装APR (Apache Portable Runtime)

http://apr.apache.org/download.cgi

安装 APR,prefix后面跟着的是你想要安装APR的路径,前提:进入到解压后的APR路径

./configure –prefix=/usr/local/apr
make
make install

1.3. 安装APR-Util

前提:进入到解压后的APR-Util路径,prefix后面跟着的是你想要安装APR的路径,-with-apr是指向我们安装apr的路径

./configure –prefix=/usr/local/apr-util -with-apr=/usr/local/apr/
make
make install

1.4. 重新安装Apache HTTP Server

进入到http server的解压路径,执行下列命令
前提:记得创建/usr/local/httpd/这个路径

./configure –prefix=/usr/local/httpd/ -with-apr=/usr/local/apr -with-apr-util=/usr/local/apr-util/
make

make install

进入到httpd的安装目录,启动服务

cd /usr/local/httpd/bin
apachectl -k start

遇到“AH00558: httpd: Could not reliably determine the server’s fully qualified domain name”错误

进入到/usr/local/httpd/conf目录

编辑httpd.conf文件,搜索”#ServerName”,添加ServerName localhost:80

重新进入/usr/local/httpd/bin

apachectl -k start

在浏览器中输入localhost:80

2. 开启ab测试

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
$ ab
ab: wrong number of arguments
Usage: ab [options] [http[s]://]hostname[:port]/path
Options are:
-n requests Number of requests to perform
-c concurrency Number of multiple requests to make at a time
-t timelimit Seconds to max. to spend on benchmarking
This implies -n 50000
-s timeout Seconds to max. wait for each response
Default is 30 seconds
-b windowsize Size of TCP send/receive buffer, in bytes
-B address Address to bind to when making outgoing connections
-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 to use for POST/PUT data, 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.
-q Do not show progress when doing more than 150 requests
-l Accept variable document length (use this for dynamic pages)
-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.
-m method Method name
-h Display usage information (this message)
-I Disable TLS Server Name Indication (SNI) extension
-Z ciphersuite Specify SSL/TLS cipher suite (See openssl ciphers)
-f protocol Specify SSL/TLS protocol
(TLS1, TLS1.1, TLS1.2 or ALL)
-E certfile Specify optional client certificate chain and private key

测试

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
$ ab -n 10000 http://localhost:9500/edu-teacher/listTeachers
This is ApacheBench, Version 2.3 <$Revision: 1843412 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests


Server Software:
Server Hostname: localhost
Server Port: 9500

Document Path: /edu-teacher/listTeachers
Document Length: 5685 bytes

Concurrency Level: 100
Time taken for tests: 39.782 seconds
Complete requests: 10000
Failed requests: 9885
(Connect: 0, Receive: 0, Length: 9885, Exceptions: 0)
Total transferred: 59491075 bytes
HTML transferred: 56781075 bytes
Requests per second: 251.37 [#/sec] (mean)
Time per request: 397.820 [ms] (mean)
Time per request: 3.978 [ms] (mean, across all concurrent requests)
Transfer rate: 1460.38 [Kbytes/sec] received

Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 1 6.5 0 83
Processing: 44 371 250.6 309 6235
Waiting: 41 366 245.3 306 6117
Total: 44 372 254.0 309 6235

Percentage of the requests served within a certain time (ms)
50% 309
66% 349
75% 386
80% 415
90% 544
95% 710
98% 964
99% 1313
100% 6235 (longest request)
本文结束  感谢您的阅读
  • 本文作者: Wang Ting
  • 本文链接: /zh-CN/2020/04/19/压力测试工具-ApacheAB/
  • 发布时间: 2020-04-19 15:43
  • 更新时间: 2021-12-14 15:02
  • 版权声明: 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!