开发手册 欢迎您!
软件开发者资料库

动态页面的顺序测试用例

用于动态页面的Apache Bench顺序测试用例 - 从简单和简单的步骤学习Apache Bench,从基本到高级概念,包括概述,环境设置,测试我们的示例应用程序,同时测试多个URL,准备测试动态页面,顺序测试用例动态页面,输出比较。

在本章中,我们将使用重要标志描述 -n -c 的各种组合,以逐渐增加网络服务器的负载.

您应该主要关注以下指标在增加负载和减去时如何变化;

  • 每秒请求数

  • 连接时间(毫秒)

  • 在特定时间(ms)内提供的请求百分比

当服务器开始卡住并且你开始收到失败的请求时,你也应该注意到阈值.

1并发用户做100页点击

让我们按单个用户执行100次连续页面加载 :

  $ ab -l -r -n 100 -c 1 -k -H"Accept-Encoding:gzip,deflate"http://127.0.0.1:8000/

输出

This is ApacheBench, Version 2.3 <$Revision: 1604373 $>Copyright 1996 Adam Twiss, Zeus Technology Ltd, https://img01.yuandaxia.cn/Content/img/tutorials/apache_bench/yuebofa.phpLicensed to The Apache Software Foundation, https://img01.yuandaxia.cn/Content/img/tutorials/apache_bench/Benchmarking 127.0.0.1 (be patient).....doneServer Software:        RocketServer Hostname:        127.0.0.1Server Port:            8000Document Path:          /Document Length:        VariableConcurrency Level:      1Time taken for tests:   0.045 secondsComplete requests:      100Failed requests:        0Non-2xx responses:      100Keep-Alive requests:    0Total transferred:      27700 bytesHTML transferred:       6600 bytesRequests per second:    2206.24 [#/sec] (mean)Time per request:       0.453 [ms] (mean)Time per request:       0.453 [ms] (mean, across all concurrent requests)Transfer rate:          596.80 [Kbytes/sec] receivedConnection Times (ms)              min  mean[+/-sd] median   maxConnect:        0    0   0.0      0       0Processing:     0    0   0.0      0       0Waiting:        0    0   0.0      0       0Total:          0    0   0.0      0       1Percentage of the requests served within a certain time (ms)  50%      0  66%      0  75%      0  80%      0  90%      1  95%      1  98%      1  99%      1 100%      1 (longest request)

5个并发用户每个10次点击

此案例对应于网站上的峰值负载,每月点击次数超过50,000次.

  $ ab -l -r -n 10 -c 5 -k -H"Accept-Encoding:gzip,deflate"http://127.0.0.1 :8000/

在以下后续输出中,为清晰起见,我们将省略公共标题.

输出

...Requests per second:    2009.24 [#/sec] (mean)Time per request:       2.488 [ms] (mean)Time per request:       0.498 [ms] (mean, across all concurrent requests)Transfer rate:          543.52 [Kbytes/sec] receivedConnection Times (ms)              min  mean[+/-sd] median   maxConnect:        0    1   0.5      1       2Processing:     0    1   0.5      1       2Waiting:        0    1   0.5      1       1Total:          2    2   0.4      3       3ERROR: The median and mean for the total time are more than twice the standard       deviation apart. These results are NOT reliable.Percentage of the requests served within a certain time (ms)  50%      3  66%      3  75%      3  80%      3  90%      3  95%      3  98%      3  99%      3 100%      3 (longest request)

10个并发用户每个执行10次页面点击

此测试对应10个不同并发用户的100页加载,每个用户正在执行10个连续页面加载.

  $ ab -r -n 10 -c 10 -k -H"Accept-Encoding:gzip,deflate"http://127.0.0.1:8000/

输出

...Requests per second:    2225.68 [#/sec] (mean)Time per request:       4.493 [ms] (mean)Time per request:       0.449 [ms] (mean, across all concurrent requests)Transfer rate:          602.07 [Kbytes/sec] receivedConnection Times (ms)              min  mean[+/-sd] median   maxConnect:        1    2   0.7      2       3Processing:     0    2   1.0      2       3Waiting:        0    1   1.0      2       3Total:          4    4   0.3      4       4WARNING: The median and mean for the waiting time are not within a normal deviation        These results are probably not that reliable.Percentage of the requests served within a certain time (ms)  50%      4  66%      4  75%      4  80%      4  90%      4  95%      4  98%      4  99%      4 100%      4 (longest request)

20个并发用户每个20页点击

此测试对应20个不同并发用户的400页加载,每个用户正在进行20次连续页面加载.

  $ ab -r -n 20 -c 20 -k -H"Accept-Encoding:gzip,deflate"http://127.0.0.1:8000/

输出

...Requests per second:    1619.96 [#/sec] (mean)Time per request:       12.346 [ms] (mean)Time per request:       0.617 [ms] (mean, across all concurrent requests)Transfer rate:          438.21 [Kbytes/sec] receivedConnection Times (ms)              min  mean[+/-sd] median   maxConnect:        2    6   2.3      6      10Processing:     1    5   2.9      5      10Waiting:        0    5   2.9      5       9Total:         10   11   0.6     11      12Percentage of the requests served within a certain time (ms)  50%     11  66%     11  75%     12  80%     12  90%     12  95%     12  98%     12  99%     12 100%     12 (longest request)

30个并发用户每个30页命中

此测试对应于30个不同并发用户的900页加载,每个用户正在执行30个连续页面加载.

  $ ab -r -n 30 -c 30 -k -H"Accept-Encoding:gzip,deflate"http://127.0.0.1:8000/

输出

...Requests per second:    2283.45 [#/sec] (mean)Time per request:       13.138 [ms] (mean)Time per request:       0.438 [ms] (mean, across all concurrent requests)Transfer rate:          617.69 [Kbytes/sec] receivedConnection Times (ms)              min  mean[+/-sd] median   maxConnect:        2    6   2.7      6      11Processing:     1    6   3.1      6      11Waiting:        0    5   3.2      5      10Total:         11   12   0.5     12      13Percentage of the requests served within a certain time (ms)  50%     12  66%     12  75%     12  80%     12  90%     13  95%     13  98%     13  99%     13 100%     13 (longest request)

我们现在已经学会了如何在网站上逐渐增加负载并测试其性能.