Programming

ab 부하 테스트

procodes 2020. 5. 20. 22:07
반응형

ab 부하 테스트


아파치 벤치 도구 ( ab)를 사용하여 웹 사이트를로드 테스트하는 방법을 누군가가 나를 안내 할 수 있습니까?

다음을 알고 싶습니다.

분당 얼마나 많은 사람들이 사이트를 처리 할 수 ​​있습니까?

이것을 알아 내기 위해 실행 해야하는 명령을 안내하십시오.

나는 모든 튜토리얼을 시도했지만 혼란스러워합니다.


아파치 벤치 마크 도구는 매우 기본적이며 성능에 대한 확실한 아이디어를 제공하지만 사이트에서 프로덕션 환경에 심각한 스트레스를 줄 경우에만 의존하는 것은 좋지 않습니다.

가장 일반적이고 간단한 매개 변수는 다음과 같습니다.

-c: ( "동시성"). 동시에 사이트를 방문하는 클라이언트 (사람 / 사용자) 수를 나타냅니다. ab실행 하는 동안 -c사이트를 방문하는 클라이언트가 있습니다. 이것이 실제로 벤치 마크 동안 사이트가 겪을 스트레스의 양을 결정합니다.

-n: 몇 건의 요청을할지 나타냅니다. 벤치 마크의 길이 만 결정합니다. 서버가 지원할 수 -n있는 -c가치를 가진 높은 가치 는 스트레스가 지속될 때 문제가 발생하지 않도록하는 것이 좋습니다. 5 시간 동안 5 초 동안 스트레스를 지원하는 것은 다릅니다.

-k: "KeepAlive"기능 브라우저는 기본적으로 수행합니다. -k"부울"이므로 값을 전달할 필요가 없습니다 (즉, 테스트에서 HTTP의 Keep Alive 헤더를 사용하고 연결을 유지하기를 원함을 나타냅니다). 브라우저가이 작업을 수행하고 브라우저에서 사이트가 가져 오는 스트레스와 흐름을 시뮬레이트하고 싶을 수 있으므로이를 벤치마킹하는 것이 좋습니다.

마지막 주장은 단순히 호스트입니다. 지정하지 않으면 기본적으로 http : // 프로토콜이 적용됩니다.

ab -k -c 350 -n 20000 example.com/

위의 명령을 실행하면 2 만 건의 요청이 충족 될 때까지 350 개의 동시 연결로 http://example.com/ 을 누르게됩니다. 연결 유지 헤더를 사용하여 수행됩니다.

프로세스가 2 만 건의 요청을 완료하면 통계에 대한 피드백을받습니다. 이것은 위의 매개 변수를 사용할 때 사이트가 얼마나 스트레스를 받아 수행했는지를 알려줍니다.

사이트에서 동시에 처리 할 수있는 사람 수를 알아 보려면 응답 시간 (평균, 최소 및 최대 응답 시간, 요청 실패 등)이 사이트에서 허용 할 수있는 숫자인지 확인하십시오 (다른 사이트는 다른 속도를 원할 수 있음). "확장하면 요청이 실패하고 중단됩니다"라고 말하는 지점에 도달 할 때까지 다른 -c 값으로 도구를 실행할 수 있습니다.

웹 사이트에 따라 분당 평균 요청 수가 예상됩니다. 이것은 매우 다양하므로 ab로 이것을 시뮬레이션 할 수 없습니다. 그러나 다음과 같이 생각하십시오. 평균 사용자가 분당 5 개의 요청을 받고 평균 응답 시간이 2 초인 경우, 분당 10 초는 1 명의 사용자가 요청에 있음을 의미합니다. 사이트를 방문 할 시간의 1/6 이것은 또한 6 명의 사용자가 동시에 ab를 사용하여 사이트를 방문하는 경우 동시성 레벨 (-c)이 6에 불과하더라도 시뮬레이션에 36 명의 사용자가있을 가능성이 있음을 의미합니다.

이는 사이트를 사용하는 사용자에게 예상되는 동작에 따라 다르지만 "사용자가 분당 X 개의 요청을받을 것으로 예상하고 평균 응답 시간이 2 초인 경우 유효한 것으로 간주합니다"에서 얻을 수 있습니다. 그런 다음 평균 응답 시간이 2 초가 될 때까지 -c 레벨을 수정하고 (최대 응답 시간과 stddev가 여전히 유효한지 확인) -c를 얼마나 크게 만들 수 있는지 확인하십시오.

나는 이것을 분명히 설명하기를 바랍니다 :) 행운을 빈다


이것을 알아 내기 위해 실행 해야하는 명령을 안내하십시오.

가장 간단한 테스트는 한 번에 10 개의 요청을 한 번에 10 개씩 수행하는 것입니다 (테스트 기간 동안 10 명의 동시 사용자가 각각 100 페이지 씩을받는 것을 대략 시뮬레이션합니다).

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

-n 1000 요청 횟수입니다.

-c 10 동시 방문자 (순차 방문자)를 더 잘 시뮬레이션하기 위해 한 번에 하나의 요청 대신 한 번에 10 개의 요청을 수행하도록 AB에 지시합니다.

-kKeepAlive웹 서버에 요청을 한 후 연결을 종료하지 말고 계속 재사용하도록 요청 하는 헤더를 보냅니다 .

Accept-Encoding: gzip, deflatemod_deflate는 거의 항상 텍스트 / html 출력을 25 % -75 %로 압축하는 데 사용되기 때문에 추가 헤더를 보내고 있습니다. 이는 웹 서버의 전체 성능에 영향을 미치므로 그 영향을 무시해서는 안됩니다 (예 : 같은 시간에 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을 곱하면 분당 요청이 있습니다.

실제 결과를 얻으려면 복잡한 PHP 코드 및 여러 MySQL 쿼리를 포함하여 모든 기능이 어떻게 작동하는지 알아야하므로 정적 HTML 또는 index.php 파일 대신 Wordpress를 테스트해야합니다.

예를 들어 다음은 동일한 시스템 및 WAMP 환경에서 Wordpress를 새로 설치 한 결과를 테스트 한 결과입니다 (WampDeveloper를 사용하고 있지만 Xampp, WampServer 등도 있습니다) ...

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

지금은 37 배 더 느립니다!

로드 테스트 후 전체 성능 (초당 요청 수)을 개선하고 더 큰로드 (예 : Apache 증가 -n-cApache 충돌) 에서 웹 서버를보다 안정적으로 만들기 위해 수행 할 수있는 여러 가지 작업이 있습니다. 당신은 여기에 대해 읽을 수 있습니다 :

AB를 사용한 Apache로드 테스트 (Apache Bench)


Steps to set up Apache Bench(AB) on windows (IMO - Recommended).

Step 1 - Install Xampp.
Step 2 - Open CMD.
Step 3 - Go to the apache bench destination (cd C:\xampp\apache\bin) from CMD
Step 4 - Paste the command (ab -n 100 -c 10 -k -H "Accept-Encoding: gzip, deflate" http://localhost:yourport/)
Step 5 - Wait for it. Your done


Load testing your API by using just ab is not enough. However, I think it's a great tool to give you a basic idea how your site is performant.

If you want to use the ab command in to test multiple API endpoints, with different data, all at the same time in background, you need to use "nohup" command. It runs any command even when you close the terminal.

I wrote a simple script that automates the whole process, feel free to use it: http://blog.ikvasnica.com/entry/load-test-multiple-api-endpoints-concurrently-use-this-simple-shell-script


I was also curious if I can measure the speed of my script with apache abs or a construct / destruct php measure script or a php extension.

the last two have failed for me: they are approximate. after which I thought to try "ab" and "abs".

the command "ab -k -c 350 -n 20000 example.com/" is beautiful because it's all easier!

but did anyone think to "localhost" on any apache server for example www.apachefriends.org?

you should create a folder such as "bench" in root where you have 2 files: test "bench.php" and reference "void.php".

and then: benchmark it!

bench.php

<?php

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

void.php

<?php
?>

on your Desktop you should use a .bat file(in Windows) like this:

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

Now if you pay attention closely ...

the void script isn't produce zero results !!! SO THE CONCLUSION IS: from the second result the first result should be decreased!!!

here i got :

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 the result i expect !

참고URL : https://stackoverflow.com/questions/12732182/ab-load-testing

반응형