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

Apache Bench - 对输出的比较

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

在本章中,我们将比较带有和不带标志的输出.让我们看看使用适当的标志如何提高Web应用程序的性能.在此之前,我们需要了解您的应用程序如何简单,然后您可能不会注意到差异.就像我们的简单应用程序一样,带有标志和没有标志.然后我们将使用 https://www.apache.org/网址执行相同的测试,看看差异.

测试没有标志的应用程序

在本节中,我们将了解如何在没有标志的情况下测试我们的应用程序.

  $ ab -n 100 -c 10 http://127.0.0.1:8000/

输出

This is ApacheBench, Version 2.3 <$Revision: 1604373 $>Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/Licensed to The Apache Software Foundation, http://www.apache.org/Benchmarking 127.0.0.1 (be patient).....doneServer Software:        RocketServer Hostname:        127.0.0.1Server Port:            8000Document Path:          /Document Length:        VariableConcurrency Level:      10Time taken for tests:   0.244 secondsComplete requests:      100Failed requests:        0Non-2xx responses:      100Keep-Alive requests:    0Total transferred:      27700 bytesHTML transferred:       6600 bytesRequests per second:    2208.77 [#/sec] (mean)Time per request:       4.527 [ms] (mean)Time per request:       0.453 [ms] (mean, across all concurrent requests)Transfer rate:          597.49 [Kbytes/sec] receivedConnection Times (ms)              min  mean[+/-sd] median   maxConnect:        1    2   0.7      2       3Processing:     0    2   0.7      2       4Waiting:        0    2   1.0      2       3Total:          4    4   0.3      4       5Percentage of the requests served within a certain time (ms)  50%      4  66%      4  75%      5  80%      5  90%      5  95%      5  98%      5  99%      5 100%      5 (longest request)

使用标志测试我们的应用程序

在本节中,我们将了解如何使用标志测试我们的应用程序.

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

输出

...Requests per second:    2277.07 [#/sec] (mean)Time per request:       4.392 [ms] (mean)Time per request:       0.439 [ms] (mean, across all concurrent requests)Transfer rate:          615.97 [Kbytes/sec] receivedConnection Times (ms)              min  mean[+/-sd] median   maxConnect:        1    2   0.7      2       3Processing:     0    2   0.7      2       4Waiting:        0    2   1.0      2       3Total:          4    4   0.2      4       5Percentage of the requests served within a certain time (ms)  50%      4  66%      4  75%      4  80%      4  90%      5  95%      5  98%      5  99%      5 100%      5 (longest request)

我们可以简单地注意到输出之间没有太大差异统计.

测试没有标志的Apache组织网站

现在让我们看看如何测试没有标志的Apache组织网站.

  $ ab -n 100 -c 10 http://www.apache.org/

输出

This is ApacheBench, Version 2.3 <$Revision: 1604373 $>Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/Licensed to The Apache Software Foundation, http://www.apache.org/Benchmarking www.apache.org (be patient).....doneServer Software:        Apache/2.4.7Server Hostname:        www.apache.orgServer Port:            80Document Path:          /Document Length:        58433 bytesConcurrency Level:      10Time taken for tests:   1.498 secondsComplete requests:      100Failed requests:        0Total transferred:      5877500 bytesHTML transferred:       5843300 bytesRequests per second:    66.74 [#/sec] (mean)Time per request:       149.840 [ms] (mean)Time per request:       14.984 [ms] (mean, across all concurrent requests)Transfer rate:          3830.58 [Kbytes/sec] receivedConnection Times (ms)              min  mean[+/-sd] median   maxConnect:       12  110 295.2     12    1012Processing:    37   38   0.5     38      39Waiting:       12   13   0.3     13      15Total:         49  147 295.4     50    1051Percentage of the requests served within a certain time (ms)  50%     50  66%     50  75%     50  80%     50  90%    816  95%   1050  98%   1051  99%   1051 100%   1051 (longest request)

使用标志测试Apache组织网站

现在让我们用Flags测试Apache Organization网站.

$ ab -l -r -n 100 -c 10 -k -H "Accept-Encoding: gzip, deflate"  http://www.apache.org/

输出

...Document Length:        VariableConcurrency Level:      10Time taken for tests:   0.357 secondsComplete requests:      100Failed requests:        0Keep-Alive requests:    100Total transferred:      1358510 bytesHTML transferred:       1317700 bytesRequests per second:    280.28 [#/sec] (mean)Time per request:       35.678 [ms] (mean)Time per request:       3.568 [ms] (mean, across all concurrent requests)Transfer rate:          3718.41 [Kbytes/sec] receivedConnection Times (ms)              min  mean[+/-sd] median   maxConnect:        0    1   3.7      0      12Processing:    14   17  21.3     15     227Waiting:       14   17  21.3     14     227Total:         14   18  21.5     15     227Percentage of the requests served within a certain time (ms)  50%     15  66%     15  75%     15  80%     15  90%     27  95%     28  98%     29  99%    227 100%    227 (longest request)

您可以简单地注意每秒的请求如何随着标志的使用而增加.在本例中,特别是由于使用了 -H"Accept-Encoding:gzip ,因为该标志告诉Apache服务器以 gzip 格式提供请求.

考虑Apache Bench结果

Apache Bench结果需要考虑几个要点.这将有助于我们设计消除应用程序瓶颈并提高性能的整体策略.

我们需要每秒请求数.这让我们了解我们的Web服务器设置是如何运行的;数字越大,性能越好.然后是连接时间(ms)和服务请求的百分比.您可能需要调整Web服务器的设置以将这些指标更改为您期望的性能.

检查Apache或使用过的Web服务器错误日志或(一般)日志中是否有错误.随着您的负载增加,事情将开始窒息:内存问题将启动升起如果不考虑并发性,许多python脚本将开始崩溃.

您需要找出Web服务器崩溃的关键并发值和/或倍出?通常,这应该发生在相当高的并发级别.如果此值较低,则表示出现问题,您需要将这些设置调低或调低.

结论

在本教程中,我们学习了Apache的用法Bench可用于加载测试任何网站或Web应用程序. Apache Bench可以是一个非常有价值的工具,用于确定应如何改进Web应用程序服务器设置,以减少瓶颈并提高性能.现在您已熟悉Apache Bench的基本用法,您可以从创建新的测试计划开始,以便在各种情况下测量应用程序的性能.