Apache Bench – 输出比较

Apache Bench – 输出比较


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

在没有标志的情况下测试我们的应用程序

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

$ 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).....done


Server Software:        Rocket
Server Hostname:        127.0.0.1
Server Port:            8000

Document Path:          /
Document Length:        Variable

Concurrency Level:      10
Time taken for tests:   0.244 seconds
Complete requests:      100
Failed requests:        0
Non-2xx responses:      100
Keep-Alive requests:    0
Total transferred:      27700 bytes
HTML transferred:       6600 bytes
Requests 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] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        1    2   0.7      2       3
Processing:     0    2   0.7      2       4
Waiting:        0    2   1.0      2       3
Total:          4    4   0.3      4       5

Percentage 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] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        1    2   0.7      2       3
Processing:     0    2   0.7      2       4
Waiting:        0    2   1.0      2       3
Total:          4    4   0.2      4       5

Percentage 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).....done

Server Software:        Apache/2.4.7
Server Hostname:        www.apache.org
Server Port:            80

Document Path:          /
Document Length:        58433 bytes

Concurrency Level:      10
Time taken for tests:   1.498 seconds
Complete requests:      100
Failed requests:        0
Total transferred:      5877500 bytes
HTML transferred:       5843300 bytes
Requests 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] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:       12  110 295.2     12    1012
Processing:    37   38   0.5     38      39
Waiting:       12   13   0.3     13      15
Total:         49  147 295.4     50    1051

Percentage 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 组织网站

现在让我们用标志测试 Apache 组织网站。

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

输出

...
Document Length:        Variable

Concurrency Level:      10
Time taken for tests:   0.357 seconds
Complete requests:      100
Failed requests:        0
Keep-Alive requests:    100
Total transferred:      1358510 bytes
HTML transferred:       1317700 bytes
Requests 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] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   3.7      0      12
Processing:    14   17  21.3     15     227
Waiting:       14   17  21.3     14     227
Total:         14   18  21.5     15     227

Percentage 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 , deflate ,因为这个标志告诉 Apache 服务器以gzipped格式提供请求

考虑 Apache Bench 结果

当涉及到 Apache Bench 结果时,需要考虑几个要点。这将帮助我们设计整体策略以消除应用程序中的瓶颈并提高其性能。

我们需要每秒请求数。这让我们了解我们的网络服务器设置的工作情况;数字越大,性能越好。然后是连接时间 (ms) 和服务请求的百分比。您可能需要调整 Web 服务器的设置以将这些指标更改为您想要的性能。

检查 Apache 或使用的 Web 服务器错误日志或(一般)日志中是否存在错误。当您增加负载时,事情将开始变得困难:内存问题将开始出现。如果编写时没有考虑到并发性,许多 python 脚本将开始崩溃。

您需要找出您的 Web 服务器崩溃和/或超时的临界并发值是多少?通常这应该发生在相当高的并发级别。如果此值较低,则说明有问题,您需要将这些设置调低/调高。

结论

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

觉得文章有用?

点个广告表达一下你的爱意吧 !😁