성능 테스트
아파치벤치(ApacheBench, ab) 활용
hippo 데브옵스
2023. 9. 15. 03:18
- AB(Apache HTTP server benchmarking tool)는 커맨드 라인을 활용한 매우 가볍고 유용한 웹서버 벤치마킹 도구
- 간단한 REST API나 정적 컨텐츠에 대한 성능 테스트 시에 빠르고 간편하게 벤치마킹 정보를 얻어올 수 있음
- 성능개선 작업을 진행하면서 수정된 API에 대해서 개발환경에는 ngrinder를 활용
- 운영환경에는 간단한 설치만으로 테스트 가능한 ApacheBench를 활용
- Apache Bench의 공식 URL : https://httpd.apache.org/docs/2.4/en/programs/ab.html
ab - Apache HTTP server benchmarking tool - Apache HTTP Server Version 2.4
ab - Apache HTTP server benchmarking tool ab is a tool for benchmarking your Apache Hypertext Transfer Protocol (HTTP) server. It is designed to give you an impression of how your current Apache installation performs. This especially shows you how many req
httpd.apache.org
ApacheBench를 사용하는 경우
- ApacheBench는 웹서버 쪽 성능 측정을 위해 만들어진 도구
- ApacheBench는 세션을 사용한 복잡한 인증 절차 등을 포함한 페이지를 테스트하기에는 부적합
- ApacheBench는 간단한 API(헤더 정보는 활용할 수 있으니)나 정적컨텐츠의 서비스 성능 측정에는 적합
- ApacheBench는 웹서버가 설치되어 있는 머신의 한계치를 측정하거나 튜닝할 때, 간단하게 response time의 성능 정보 측정
ApacheBench 사용 시 참고사항 → 참고할 만한 이슈
- HTML이나 CSS, image 등은 해석하지 않음 → 단순히 response 시간만 나타내줌
- HTTP 1.0 클라이언트를 사용
- 동적 페이지는 Centent-Length 헤더 내용을 미리 작성할 수 없기 때문에 -k KeepAlive 옵션이 동작하지 않음
- HTTP 1.0클라이언트이기 때문에 Transfer-Encoding : chunked 옵션은 사용할 수 없음
- request 간에 delay를 주는 옵션은 없으므로 DDOS attack으로 간주 될 수 있음
AB 설치법
# Redhat / Centos
$ yum install httpd-tools
# ubuntu 설치
$ sudo apt-get install apache2-utils
AB 명령어 사용 방법
$ ab
Usage: ab [options] [http[s]://]hostname[:port]/path
AB 명령어 자주 사용하는 옵션
옵션 | 설명 |
-n | - 성능을 검사하기위해 보내는 요청수. - 요청을 한번만 보내기 때문에 일반적인 성능 검사 결과를 얻을 수 없음 |
-c | - 동시에 요청하는 요청수 - 기본적으로 한번에 한 요청만을 보냄 |
-C | - Cookie 헤더 사용 |
-H | - 요청에 헤더 추가 |
-i | - GET 메소드 대신 HEAD 메소드 요청 |
-k | - KeepAlive 사용 - 동적 페이지는 Centent-Length 헤더 내용을 미리 작성할 수 없기 때문에 -k KeepAlive 옵션이 동작하지 않음 |
-p | - POST 메소드 요청 |
-g | - 측정한 모든 값을 'gnuplot' 혹은 TSV(Tab separate values, 탭으로 구분한 값) 파일에 기록 - 라벨은 output 파일의 첫번째 라인을 참고 |
-t | - 성능을 검사하는 최대 초단위 시간. - 내부적으로 -n 50000을 가정 - 정해진 시간동안 서버 성능을 검사할때 사용 - 기본적으로 시간 제한 없이 검사 |
-v | - 출력 수준을 지정 - 4 이상이면 헤더에 대한 정보를 출력 - 3 이상이면 (404, 202, 등) 응답코드를 출력 - 2 이상이면 경고(warning)와 정보(info)를 출력 |
-A | - 프록시를 통해 BASIC Authentication 정보를 제공 - :로 구분한 사용자명과 암호를 base64 인코딩하여 전송 |
-X | - proxy[:port] 프록시 서버를 사용하여 요청 |
AB 명령어에서 헷갈리는 대표적인 옵션 -c 옵션에 대한 설명
- -c 옵션이 기본적으로 다른 부하툴과는 다른게 동작 → 3개의 프로세스(쓰레드)가 10개씩 요청하는 것이 아니라 3개의 풀을 가지고 10번 요청을 진행
$ ab -n 10 -c 3 http://www.google.com
- -c옵션에서 숫자는 pool 개념으로 보면 됨
[1, 2, 3]
- -c 옵션에 3을 선언하였으면, 시작을 3개의 요청을 시작했고, 만약 2번이 먼저 종료됐으면 2번을 4번으로 대체 요청
[1, 4, 3]
- 1번이 종료되면 5번으로 대체 요청
[5, 4, 3]
- 3번이 종료되면 6번이 대체 요청
[5, 4, 6]
- 10개의 요청을 순차로 처리함
AB 명령어 전체 옵션
$ ab
ab: wrong number of arguments
Usage: ab [options] [http[s]://]hostname[:port]/path
Options are:
-n requests Number of requests to perform
-c concurrency Number of multiple requests to make at a time
-t timelimit Seconds to max. to spend on benchmarking
This implies -n 50000
-s timeout Seconds to max. wait for each response
Default is 30 seconds
-b windowsize Size of TCP send/receive buffer, in bytes
-B address Address to bind to when making outgoing connections
-p postfile File containing data to POST. Remember also to set -T
-u putfile File containing data to PUT. Remember also to set -T
-T content-type Content-type header to use for POST/PUT data, eg.
'application/x-www-form-urlencoded'
Default is 'text/plain'
-v verbosity How much troubleshooting info to print
-w Print out results in HTML tables
-i Use HEAD instead of GET
-x attributes String to insert as table attributes
-y attributes String to insert as tr attributes
-z attributes String to insert as td or th attributes
-C attribute Add cookie, eg. 'Apache=1234'. (repeatable)
-H attribute Add Arbitrary header line, eg. 'Accept-Encoding: gzip'
Inserted after all normal header lines. (repeatable)
-A attribute Add Basic WWW Authentication, the attributes
are a colon separated username and password.
-P attribute Add Basic Proxy Authentication, the attributes
are a colon separated username and password.
-X proxy:port Proxyserver and port number to use
-V Print version number and exit
-k Use HTTP KeepAlive feature
-d Do not show percentiles served table.
-S Do not show confidence estimators and warnings.
-q Do not show progress when doing more than 150 requests
-l Accept variable document length (use this for dynamic pages)
-g filename Output collected data to gnuplot format file.
-e filename Output CSV file with percentages served
-r Don't exit on socket receive errors.
-m method Method name
-h Display usage information (this message)
-I Disable TLS Server Name Indication (SNI) extension
-Z ciphersuite Specify SSL/TLS cipher suite (See openssl ciphers)
-f protocol Specify SSL/TLS protocol
(SSL2, TLS1, TLS1.1, TLS1.2 or ALL)
AB 명령어 출력 결과
출력 항목 | 설명 |
Server Software: Apache | - 아파치 버전 |
Server Hostname: www.naver.com | - 도메인명 |
Server Port: 80 | - 웹서비스 사용 포트 |
Document Path: / | - 초기문서가 위치하는 웹문서 root(서버 내의 절대경로가 아님) |
Document Length: 72226 bytes | - 초기문서의 용량 |
Concurrency Level: 1 | - 동시성 레벨 |
Time taken for tests: 0.016 seconds | - 응답속도 - Time taken for tests 값이 제일 중요 |
Complete requests: 1 | - 요구에 응답한 세션수 |
Failed requests: 0 | - 요구에 응답실패한 세션수 |
Broken pipe errors: 0 | - 실패한 에러수 |
Total transferred: 72539 bytes | - 총 전송 바이트수 |
HTML transferred: 72226 bytes | - 총 전송한 HTML 바이트수 |
Requests per second: 62.50 【#/sec】 (mean) |
- 초당 응답요구수 |
Time per request: 16.00 【ms】 (mean) |
- 요구에 응답한 시간 - Time per request 값이 중요 |
Time per request: 16.00 【ms】 (mean, across all concurrent requests) |
- 요구에 응답한 시간 |
Transfer rate: 4533.69 【Kbytes/sec】 received |
- 초당 전송 가능한 용량 |
Client 측 ab 부하테스트 호출 테스트
1. 요청 400, 동시접속자 1
$ ab -n 400 -c 1 http://[도메인]:80/while.jsp
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking [도메인] (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Finished 400 requests
Server Software:
Server Hostname: [도메인]
Server Port: 80
Document Path: /while.jsp
Document Length: 2 bytes
Concurrency Level: 1
Time taken for tests: 10.191 seconds ### 총 시간
Complete requests: 400
Failed requests: 0 ### 에러 수
Write errors: 0
Total transferred: 97200 bytes
HTML transferred: 800 bytes
Requests per second: 39.25 [#/sec] (mean) ==> 초당 처리 Request 수
Time per request: 25.476 [ms] (mean) ==> Request 당 처리 시간
Time per request: 25.476 [ms] (mean, across all concurrent requests)
Transfer rate: 9.31 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.0 0 1
Processing: 21 25 5.7 23 59
Waiting: 21 25 5.7 23 59
Total: 21 25 5.7 23 59
Percentage of the requests served within a certain time (ms)
50% 23
66% 25
75% 28
80% 28
90% 30
95% 37
98% 44
99% 53
100% 59 (longest request)
2. 요청 400, 동시접속자 2
$ ab -n 400 -c 2 http://[도메인]:80/while.jsp
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking [도메인] (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Finished 400 requests
Server Software:
Server Hostname: [도메인]
Server Port: 80
Document Path: /while.jsp
Document Length: 2 bytes
Concurrency Level: 2
Time taken for tests: 10.103 seconds
Complete requests: 400
Failed requests: 0
Write errors: 0
Total transferred: 97200 bytes
HTML transferred: 800 bytes
Requests per second: 39.59 [#/sec] (mean)
Time per request: 50.514 [ms] (mean)
Time per request: 25.257 [ms] (mean, across all concurrent requests)
Transfer rate: 9.40 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.0 0 1
Processing: 22 50 16.1 49 152
Waiting: 22 50 16.1 49 152
Total: 22 50 16.1 49 152
Percentage of the requests served within a certain time (ms)
50% 49
66% 53
75% 58
80% 63
90% 73
95% 77
98% 87
99% 94
100% 152 (longest request)
3. 요청 400, 동시접속자 10
$ ab -n 400 -c 10 http://[도메인]:80/while.jsp
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking [도메인] (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Finished 400 requests
Server Software:
Server Hostname: [도메인]
Server Port: 80
Document Path: /while.jsp
Document Length: 2 bytes
Concurrency Level: 10
Time taken for tests: 10.262 seconds
Complete requests: 400
Failed requests: 0
Write errors: 0
Total transferred: 97200 bytes
HTML transferred: 800 bytes
Requests per second: 38.98 [#/sec] (mean)
Time per request: 256.540 [ms] (mean)
Time per request: 25.654 [ms] (mean, across all concurrent requests)
Transfer rate: 9.25 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.0 0 1
Processing: 24 254 111.9 240 681
Waiting: 24 254 111.9 240 681
Total: 24 254 111.9 241 682
Percentage of the requests served within a certain time (ms)
50% 241
66% 289
75% 338
80% 364
90% 408
95% 443
98% 500
99% 560
100% 682 (longest request)
4. 요청 400, 동시접속자 20
$ ab -n 400 -c 20 http://[도메인]:80/while.jsp
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking [도메인] (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Finished 400 requests
Server Software:
Server Hostname: [도메인]
Server Port: 80
Document Path: /while.jsp
Document Length: 2 bytes
Concurrency Level: 20
Time taken for tests: 10.454 seconds
Complete requests: 400
Failed requests: 0
Write errors: 0
Total transferred: 97200 bytes
HTML transferred: 800 bytes
Requests per second: 38.26 [#/sec] (mean)
Time per request: 522.718 [ms] (mean)
Time per request: 26.136 [ms] (mean, across all concurrent requests)
Transfer rate: 9.08 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.2 0 3
Processing: 24 514 273.4 515 1592
Waiting: 24 514 273.5 515 1592
Total: 25 514 273.4 515 1592
Percentage of the requests served within a certain time (ms)
50% 515
66% 624
75% 676
80% 711
90% 822
95% 996
98% 1230
99% 1284
100% 1592 (longest request)
5. 요청 400, 동시접속자 50
$ ab -n 400 -c 50 http://[도메인]:80/while.jsp
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking [도메인] (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Finished 400 requests
Server Software:
Server Hostname: [도메인]
Server Port: 80
Document Path: /while.jsp
Document Length: 2 bytes
Concurrency Level: 50
Time taken for tests: 10.614 seconds
Complete requests: 400
Failed requests: 0
Write errors: 0
Total transferred: 97200 bytes
HTML transferred: 800 bytes
Requests per second: 37.69 [#/sec] (mean)
Time per request: 1326.737 [ms] (mean)
Time per request: 26.535 [ms] (mean, across all concurrent requests)
Transfer rate: 8.94 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.4 0 2
Processing: 25 1264 411.7 1265 2826
Waiting: 23 1264 411.7 1265 2826
Total: 25 1264 411.5 1266 2827
Percentage of the requests served within a certain time (ms)
50% 1266
66% 1418
75% 1506
80% 1561
90% 1780
95% 1948
98% 2222
99% 2323
100% 2827 (longest request)
6. 요청 400, 동시접속자 100
$ ab -n 400 -c 100 http://[도메인]:80/while.jsp
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking [도메인] (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Finished 400 requests
Server Software:
Server Hostname: [도메인]
Server Port: 80
Document Path: /while.jsp
Document Length: 2 bytes
Concurrency Level: 100
Time taken for tests: 10.580 seconds
Complete requests: 400
Failed requests: 0
Write errors: 0
Total transferred: 97200 bytes
HTML transferred: 800 bytes
Requests per second: 37.81 [#/sec] (mean)
Time per request: 2645.001 [ms] (mean)
Time per request: 26.450 [ms] (mean, across all concurrent requests)
Transfer rate: 8.97 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 1 1.4 0 5
Processing: 28 2377 679.8 2498 3706
Waiting: 23 2376 679.8 2498 3706
Total: 29 2378 678.8 2499 3706
Percentage of the requests served within a certain time (ms)
50% 2499
66% 2675
75% 2807
80% 2840
90% 2995
95% 3176
98% 3394
99% 3534
100% 3706 (longest request)
7. 요청 400, 동시접속자 200
$ ab -n 400 -c 200 http://[도메인]:80/while.jsp
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking [도메인] (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Finished 400 requests
Server Software:
Server Hostname: [도메인]
Server Port: 80
Document Path: /while.jsp
Document Length: 2 bytes
Concurrency Level: 200
Time taken for tests: 9.756 seconds
Complete requests: 400
Failed requests: 0
Write errors: 0
Total transferred: 97200 bytes
HTML transferred: 800 bytes
Requests per second: 41.00 [#/sec] (mean)
Time per request: 4877.980 [ms] (mean)
Time per request: 24.390 [ms] (mean, across all concurrent requests)
Transfer rate: 9.73 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 3 3.2 2 9
Processing: 32 3750 1525.0 4534 6111
Waiting: 22 3750 1524.9 4528 6111
Total: 32 3753 1522.0 4535 6111
Percentage of the requests served within a certain time (ms)
50% 4535
66% 4719
75% 4896
80% 4978
90% 5173
95% 5265
98% 5612
99% 5727
100% 6111 (longest request)
테스트 시나리오 결과 해석
1. 본 테스트의 시나리오는 전체 요청 수인 400 Request를 처리
2. 동시 요청이 1, 2, 10, 20, 50, 100, 200일 경우 성능의 변화를 모니터링하는 것
요청 | 동시 접속 | 총소요시간(Sec) | 실패 | 초당처리속도 | 개별처리속도(Sec) |
400 | 1 | 10.191 | 0 | 39.25 | 0.025476 / 1 |
400 | 2 | 10.103 | 0 | 39.59 | 0.050514 / 2 |
400 | 10 | 10.262 | 0 | 38.98 | 0.25654 / 10 |
400 | 20 | 10.454 | 0 | 38.26 | 0.522718 / 20 |
400 | 50 | 10.614 | 0 | 37.69 | 1.326737 / 50 |
400 | 100 | 10.58 | 0 | 37.81 | 2.645001 / 100 |
400 | 200 | 9.756 | 0 | 41 | 4.87798 / 200 |
3. 동시 접속자가 늘어나도 초당 처리 속도는 비슷하게 측정 → 400 / 200 (총 요청 수 / 동시 요청 수)일 경우 초당 처리 요청이 가능 많음
4. Single Instance의 처리 속도 아래 표의 결과는 LoadBalancer를 두고 처리할 성능 지표
요청 | 동시 접속 | 총소요시간(Sec) | 실패 | 초당처리속도 | 개별처리속도(Sec) |
400 | 200 | 9.163 | 0 | 43.65 | 2.811523 |
5. 한대의 서버에서 테스트가 힘들면, 서버의 대수를 늘리면 됨
6. 수동의 작업들을 완전히 자동화 해주는 오토스켈링(AutoScaling)과 ELB가 만나게 되면 엄청난 시너지 효과를 내타냄
참고 URL