有人能告诉我如何使用apache bench工具(ab)加载测试我的网站的过程吗?

我想了解以下几点:

网站每分钟能处理多少人?

请引导我通过我应该运行的命令来解决这个问题。

我尝试了每一个教程,它们都令人困惑。


当前回答

我也很好奇,如果我可以测量我的脚本与apache abs或构造/销毁php测量脚本或php扩展的速度。

最后两个对我来说是失败的:它们是近似的。 然后我想试试“腹肌”和“腹肌”。

命令“ab -k -c 350 -n 20000 example.com/”非常漂亮,因为它更简单!

但是有人想过在apache服务器(例如www.apachefriends.org)上使用“localhost”吗?

你应该在根目录下创建一个文件夹,比如“bench”,其中有两个文件:测试“bench.php”和引用“void.php”。

然后:基准测试!

bench.php

<?php

for($i=1;$i<50000;$i++){
    print ('qwertyuiopasdfghjklzxcvbnm1234567890');
}
?>

void.php

<?php
?>

在你的桌面上,你应该使用。bat文件(在Windows中):

bench.bat

"c:\xampp\apache\bin\abs.exe" -n 10000 http://localhost/bench/void.php
"c:\xampp\apache\bin\abs.exe" -n 10000 http://localhost/bench/bench.php
pause

现在如果你仔细注意……

无效脚本不会产生零结果!! 所以结论是:从第二个结果来看,第一个结果应该减少!!

这里我得到:

c:\xampp\htdocs\bench>"c:\xampp\apache\bin\abs.exe" -n 10000 http://localhost/bench/void.php
This is ApacheBench, Version 2.3 <$Revision: 1826891 $>
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:        Apache/2.4.33
Server Hostname:        localhost
Server Port:            80

Document Path:          /bench/void.php
Document Length:        0 bytes

Concurrency Level:      1
Time taken for tests:   11.219 seconds
Complete requests:      10000
Failed requests:        0
Total transferred:      2150000 bytes
HTML transferred:       0 bytes
Requests per second:    891.34 [#/sec] (mean)
Time per request:       1.122 [ms] (mean)
Time per request:       1.122 [ms] (mean, across all concurrent requests)
Transfer rate:          187.15 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.3      0       1
Processing:     0    1   0.9      1      17
Waiting:        0    1   0.9      1      17
Total:          0    1   0.9      1      17

Percentage of the requests served within a certain time (ms)
  50%      1
  66%      1
  75%      1
  80%      1
  90%      1
  95%      2
  98%      2
  99%      3
 100%     17 (longest request)

c:\xampp\htdocs\bench>"c:\xampp\apache\bin\abs.exe" -n 10000 http://localhost/bench/bench.php
This is ApacheBench, Version 2.3 <$Revision: 1826891 $>
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:        Apache/2.4.33
Server Hostname:        localhost
Server Port:            80

Document Path:          /bench/bench.php
Document Length:        1799964 bytes

Concurrency Level:      1
Time taken for tests:   177.006 seconds
Complete requests:      10000
Failed requests:        0
Total transferred:      18001600000 bytes
HTML transferred:       17999640000 bytes
Requests per second:    56.50 [#/sec] (mean)
Time per request:       17.701 [ms] (mean)
Time per request:       17.701 [ms] (mean, across all concurrent requests)
Transfer rate:          99317.00 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.3      0       1
Processing:    12   17   3.2     17      90
Waiting:        0    1   1.1      1      26
Total:         13   18   3.2     18      90

Percentage of the requests served within a certain time (ms)
  50%     18
  66%     19
  75%     19
  80%     20
  90%     21
  95%     22
  98%     23
  99%     26
 100%     90 (longest request)

c:\xampp\htdocs\bench>pause
Press any key to continue . . .

90-17= 73,这是我期待的结果!

其他回答

请求后负载测试的最佳解决方案之一。点击这里

在windows上设置Apache Bench(AB)的步骤(IMO -推荐)。 步骤1 -安装Xampp。 步骤2 -打开CMD。 步骤3 -从CMD进入apache bench目的地(cd C:\xampp\apache\bin) 步骤4 -粘贴命令(ab -n 100 -c 10 -k - h "Accept-Encoding: gzip, deflate" http://localhost:yourport/) 第五步——等待时机。你做的

仅使用ab对API进行负载测试是不够的。然而,我认为它是一个很好的工具,可以让你对网站的性能有一个基本的了解。

如果你想使用ab命令在后台同时测试多个API端点,使用不同的数据,你需要使用“nohup”命令。即使关闭终端,它也会运行任何命令。

我写了一个简单的脚本,自动化整个过程,请随意使用:http://blog.ikvasnica.com/entry/load-test-multiple-api-endpoints-concurrently-use-this-simple-shell-script

执行步骤: 负载测试命令

步骤1 -安装Xampp。 步骤2 -打开CMD。 步骤3 -从CMD转到Apache工作台目的地(cd C:\xampp\ Apache \bin)。 步骤4—粘贴命令 ab -n 100 -c 10 -k -H "Accept-Encoding: gzip, deflate" http://localhost:port/ 第五步——等待时机。你完成


只有主命令“Get”

ab -k -c 25 -n 2000 http://192.168.1.113:3001/api/v1/filters/3

请引导我通过我应该运行的命令来解决这个问题。

您可以执行的最简单的测试是执行1000个请求,每次10个(这大致模拟了10个并发用户每个访问100个页面—在测试的长度中)。

ab -n 1000 -c 10 -k -H "Accept-Encoding: gzip, deflate" http://www.example.com/

-n 1000是发送请求的数量。

-c 10告诉AB一次执行10个请求,而不是一次执行1个请求,以更好地模拟并发访问者(而不是顺序访问者)。

-k发送KeepAlive报头,它要求web服务器在每个请求完成后不要关闭连接,而是继续重用它。

我还发送了额外的头部Accept-Encoding: gzip, deflate,因为mod_deflate几乎总是用于压缩文本/html输出25%-75% -其影响不应该被忽略,因为它对web服务器的整体性能的影响(即,可以在相同的时间内传输2倍的数据,等)。

结果:

Benchmarking www.example.com (be patient)
Completed 100 requests
...
Finished 1000 requests


Server Software:        Apache/2.4.10
Server Hostname:        www.example.com
Server Port:            80

Document Path:          /
Document Length:        428 bytes

Concurrency Level:      10
Time taken for tests:   1.420 seconds
Complete requests:      1000
Failed requests:        0
Keep-Alive requests:    995
Total transferred:      723778 bytes
HTML transferred:       428000 bytes
Requests per second:    704.23 [#/sec] (mean)
Time per request:       14.200 [ms] (mean)
Time per request:       1.420 [ms] (mean, across all concurrent requests)
Transfer rate:          497.76 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       1
Processing:     5   14   7.5     12      77
Waiting:        5   14   7.5     12      77
Total:          5   14   7.5     12      77

Percentage of the requests served within a certain time (ms)
  50%     12
  66%     14
  75%     15
  80%     16
  90%     24
  95%     29
  98%     36
  99%     41
 100%     77 (longest request)

对于最简单的解释,忽略除了这一行以外的所有内容:

Requests per second:    704.23 [#/sec] (mean)

乘以60,就得到了每分钟的请求数。

为了得到真实世界的结果,你会想要测试Wordpress而不是一些静态HTML或index.php文件,因为你需要知道所有东西是如何一起执行的:包括复杂的PHP代码和多个MySQL查询……

例如,这里是在相同的系统和WAMP环境下测试新安装的Wordpress的结果(我使用的是WampDeveloper,但也有Xampp, WampServer和其他)…

Requests per second:    18.68 [#/sec] (mean)

现在已经慢了37倍!

在负载测试之后,你可以做一些事情来提高整体性能(每秒请求数),也可以让web服务器在更大的负载下更稳定(例如,增加-n和-c会导致Apache崩溃),你可以在这里读到:

负载测试Apache与AB (Apache Bench)