티스토리 뷰

1.2023.08.14 - [분류 전체보기] - K6 성능 테스트

 

https://github.com/tsenart/vegeta

 

GitHub - tsenart/vegeta: HTTP load testing tool and library. It's over 9000!

HTTP load testing tool and library. It's over 9000! - GitHub - tsenart/vegeta: HTTP load testing tool and library. It's over 9000!

github.com

쿠버네티스(Kubernetes)는 컨테이너 오케스트레이션 플랫폼으로, 여러 개의 컨테이너화된 애플리케이션을 관리하고 배포하기 위한 효율적인 방법을 제공합니다. 쿠버네티스 성능 테스트는 시스템의 부하와 확장성을 테스트하여 쿠버네티스 클러스터의 성능과 안정성을 확인하는 과정입니다.

쿠버네티스 성능 테스트를 위한 다양한 방법과 도구가 있습니다. 이를 통해 클러스터의 성능과 확장성을 평가하고, 병목 현상을 식별하고 조치할 수 있습니다. 아래는 몇 가지 쿠버네티스 성능 테스트 관련 주제와 사용할 수 있는 도구들입니다.

  1. 부하 테스트 (Load Testing): 클러스터에 부하를 가해 얼마나 많은 트래픽과 작업을 처리할 수 있는지 확인합니다. 다양한 부하 테스트 도구를 사용할 수 있습니다.
    • Apache JMeter
    • Vegeta
    • k6
  2. 확장성 테스트 (Scalability Testing): 클러스터의 노드 수와 서비스 인스턴스 수를 조절하여 어떻게 성능이 변화하는지 테스트합니다.
  3. 성능 모니터링 (Performance Monitoring): 클러스터 내부 및 컨테이너의 성능 지표를 모니터링하여 성능 이슈를 식별합니다.
    • Prometheus
    • Grafana
  4. 프로파일링 (Profiling): 애플리케이션 내부에서 자원 사용량 및 성능 병목 현상을 파악합니다.
    • pprof (Go 프로그램용)
    • py-spy (Python 프로그램용)
  5. 클라우드 벤치마킹: 특정 클라우드 프로바이더에서 쿠버네티스 클러스터를 생성하고 성능을 테스트합니다.
    • Google Cloud Platform (GCP)
    • Amazon Web Services (AWS)
    • Microsoft Azure
  6. 오토스케일링 (Autoscaling) 테스트: 쿠버네티스의 오토스케일링 기능을 테스트하여 자동으로 리소스를 조절하는 동작을 확인합니다.

쿠버네티스 성능 테스트는 애플리케이션의 특성과 요구 사항에 따라 다양한 방법과 도구를 조합하여 수행할 수 있습니다. 성능 테스트를 통해 클러스터의 한계를 확인하고 최적의 구성을 찾을 수 있습니다.

 

"Vegeta"는 Go 언어로 작성된 오픈 소스 부하 테스트 도구로, HTTP 통신을 통해 웹 서비스의 성능 및 부하 테스트를 수행하는 데 사용됩니다. 다양한 시나리오와 설정으로 웹 서비스의 응답 시간, 처리량 및 부하 처리 능력을 테스트할 수 있습니다.

Vegeta의 주요 특징은 다음과 같습니다:

  1. 간단한 사용법: 명령줄에서 간단한 형식으로 명령을 실행하여 테스트를 시작할 수 있습니다.
  2. 다양한 설정: Vegeta를 사용하여 다양한 테스트 시나리오와 설정을 지정할 수 있습니다. 요청 간격, 동시 사용자 수, 헤더 등을 조절하여 다양한 테스트를 수행할 수 있습니다.
  3. 멀티코어 지원: 멀티코어 프로세서를 활용하여 부하를 생성하므로 높은 성능을 기대할 수 있습니다.
  4. JSON 출력: 결과를 JSON 형식으로 출력하여 성능 데이터를 분석하고 시각화할 수 있습니다.
  5. 레이트 리미트 조절: 테스트 요청 간격을 조절하여 원하는 부하 수준을 설정할 수 있습니다.

Vegeta를 사용하여 HTTP 요청을 생성하고, 이를 통해 웹 서비스의 성능과 부하 처리 능력을 평가할 수 있습니다. 다음은 간단한 예제 명령어입니다:

 

위 명령은 targets.txt 파일에 목표 URL을 작성하고, 해당 URL에 대한 1분 동안의 부하 테스트를 수행한 후 결과를 출력합니다. 더 많은 설정과 옵션은 Vegeta의 공식 문서나 온라인 자료를 참고하시기 바랍니다.

공식 GitHub 저장소: https://github.com/tsenart/vegeta

 

GitHub - tsenart/vegeta: HTTP load testing tool and library. It's over 9000!

HTTP load testing tool and library. It's over 9000! - GitHub - tsenart/vegeta: HTTP load testing tool and library. It's over 9000!

github.com

Vegeta를 사용하여 간단한 HTTP 부하 테스트를 수행하는 방법을 안내해 드리겠습니다. 아래의 단계를 따라하면 됩니다.

  1. Vegeta 설치: 먼저, Vegeta를 설치해야 합니다. 다음 명령을 사용하여 Go 언어가 설치되어 있는지 확인하고, Vegeta를 설치할 수 있습니다.

#Golang 먼저 설치!

[root@m-k8s go]# sudo yum install golang
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
epel/x86_64/metalink                                                       | 5.5 kB  00:00:00     
 * base: ftp.yz.yamagata-u.ac.jp
 * epel: ftp.yz.yamagata-u.ac.jp
 * extras: ftp.tsukuba.wide.ad.jp
 * updates: ftp.jaist.ac.jp
base                                                                       | 3.6 kB  00:00:00     
docker-ce-stable                                                           | 3.5 kB  00:00:00     
epel                                                                       | 4.7 kB  00:00:00     
extras                                                                     | 2.9 kB  00:00:00     
k6                                                                         | 2.9 kB  00:00:00     
kubernetes                                                                 | 1.4 kB  00:00:00     
updates                                                                    | 2.9 kB  00:00:00     
(1/5): k6/x86_64/primary_db                                                | 5.5 kB  00:00:01     
(2/5): updates/7/x86_64/primary_db                                         |  22 MB  00:00:02     
(3/5): kubernetes/primary                                                  | 133 kB  00:00:02     
(4/5): epel/x86_64/updateinfo                                              | 1.0 MB  00:00:03     
(5/5): epel/x86_64/primary_db                                              | 7.0 MB  00:02:40     
kubernetes                                                                                995/995
Resolving Dependencies
--> Running transaction check
---> Package golang.x86_64 0:1.19.10-1.el7 will be installed
--> Processing Dependency: golang-bin = 1.19.10-1.el7 for package: golang-1.19.10-1.el7.x86_64
--> Processing Dependency: golang-src = 1.19.10-1.el7 for package: golang-1.19.10-1.el7.x86_64

[root@m-k8s go]# go version
go version go1.19.10 linux/amd64

 

Vegeta 다운로드 및 설치
$wget https://github.com/tsenart/vegeta/releases/download/v12.8.4/vegeta_12.8.4_linux_amd64.tar.gz
$tar xfz vegeta-12.8.4-linux-amd64.tar.gz
$mv vegeta /usr/bin/vegeta

vi /etc/profile
path 추가(/usr/bin/vegeta)입력해줍니다.

사용예)

echo "GET http://<application_url>/" | vegeta attack -duration=120s | tee results.bin | vegeta report

[root@m-k8s home]# echo "GET http://192.168.29.16/" | vegeta attack -duration=120s | tee results.bin | vegeta report
Requests      [total, rate, throughput]         6000, 50.01, 0.00
Duration      [total, attack, wait]             2m0s, 2m0s, 1.268ms
Latencies     [min, mean, 50, 90, 95, 99, max]  876.461µs, 1.87ms, 1.705ms, 2.433ms, 2.898ms, 5.917ms, 24.603ms
Bytes In      [total, mean]                     3246000, 541.00
Bytes Out     [total, mean]                     0, 0.00
Success       [ratio]                           0.00%
Status Codes  [code:count]                      403:6000  
Error Set:
403 Forbidden
[root@m-k8s home]# echo 'GET http://example.com/' | vegeta attack -rate 2000 -duration 1m  | vegeta report
Requests      [total, rate, throughput]         88126, 1467.35, 603.96
Duration      [total, attack, wait]             1m7s, 1m0s, 6.601s
Latencies     [min, mean, 50, 90, 95, 99, max]  43.389µs, 2.706s, 2.873s, 5.414s, 6.386s, 7.874s, 12.122s
Bytes In      [total, mean]                     50565304, 573.78
Bytes Out     [total, mean]                     0, 0.00
Success       [ratio]                           45.68%
Status Codes  [code:count]                      0:47867  200:40259  
Error Set:
Get "http://example.com/": dial tcp: lookup example.com on 8.8.8.8:53: dial udp 8.8.8.8:53: socket: too many open files
Get "http://example.com/": dial tcp 0.0.0.0:0->[2606:2800:220:1:248:1893:25c8:1946]:80: connect: network is unreachable
Get "http://example.com/": dial tcp 0.0.0.0:0->[2606:2800:220:1:248:1893:25c8:1946]:80: socket: too many open files
Get "http://example.com/": dial tcp 0.0.0.0:0->93.184.216.34:80: socket: too many open files

https://www.scaleway.com/en/docs/tutorials/load-testing-vegeta/

 

Load Testing with Vegeta

This page shows you how to simulate load to a web application with Vegeta

www.scaleway.com

 

Vegeta로 부하 테스트 실행
120초 동안 부하 테스트를 실행하려면 다음 명령을 실행합니다.
Vegeta를 사용하여 성능을 테스트할 수 있습니다.

echo "GET http://<application_url>/" | vegeta attack -duration=120s | tee results.bin |
vegeta report

복사
위의 명령은 다음과 같은 보고서를 반환합니다.

Requests      [total, rate]            6000, 50.01
Duration      [total, attack, wait]    2m0.072491358s, 1m59.980003112s, 92.488246ms
Latencies     [mean, 50, 95, 99, max]  76.235976ms, 72.996349ms, 109.192641ms, 133.960662ms, 187.907358ms
Bytes In      [total, mean]            65862000, 10977.00
Bytes Out     [total, mean]            0, 0.00
Success       [ratio]                  100.00%
Status Codes  [code:count]             200:6000
Error Set:

복사
Requests테스트 중에 전송된 총 요청 수와 요청 비율을 보여줍니다.
Duration테스트의 총 기간, 응용 프로그램의 부하를 시뮬레이션하는 공격 기간 및 대기 시간을 
보여줍니다.
Latencies공격의 모든 요청 대기 시간과 인식된 최대 대기 시간의 평균 대기 시간, 50번째, 95번째
및 99번째 백분위수를 각각 보여줍니다.
Bytes In다음 Bytes Out을 보여줍니다.
total요청 또는 응답 본문과 함께 전송(송신) 또는 수신(수신)된 바이트 수입니다 .
mean요청 또는 응답 본문과 함께 전송(송신) 또는 수신(수신)된 바이트 수입니다 .
Success애플리케이션에 전송된 성공적인 요청의 백분위수 표시
Status Codes수신된 HTTP 응답 코드와 그 발생에 대한 카운터를 제공합니다. 상태 0코드는 요청이
전송되지 않았음을 의미합니다.
위의 예에서 볼 수 있듯이 애플리케이션에 전송된 요청의 100%가 성공했습니다.

다른 결과에 따라:

Requests      [total, rate]            6000, 50.01
Duration      [total, attack, wait]    2m9.500461177s, 1m59.980081991s, 9.520379186s
Latencies     [mean, 50, 95, 99, max]  843.903272ms, 77.954318ms, 3.744635321s, 25.164627897s, 30.000611567s
Bytes In      [total, mean]            62842863, 10473.81
Bytes Out     [total, mean]            0, 0.00
Success       [ratio]                  95.38%
Status Codes  [code:count]             0:45  200:5723  500:33  502:13  503:186
Error Set:
500 Internal Server Error
502 Bad Gateway
Get http://<application_url>/: EOF
503 Service Unavailable
Get http://<application_url>/: net/http: request canceled (Client.Timeout exceeded
while awaiting headers)

복사
위 출력에서 ​​볼 수 있듯이 애플리케이션에 전송된 요청의 95.38%만 성공했습니다.
섹션 에서 Status Code5723개의 요청이 성공했고(HTTP 코드 200) 186개의 요청이 HTTP 503 오류를 
수신했으며 13개의 요청이 HTTP 502 오류를 수신했음을 볼 수 있습니다.

이 결과는 애플리케이션이 로드를 처리하는 데 문제가 있고 최적화가 필요함을 보여줍니다.

대상 파일 설정
Vegeta는 또한 여러 엔드포인트가 있는 애플리케이션을 동시에 공격하기 위해 여러 대상을 
지원합니다. 이를 통해 Vegeta로 애플리케이션(예: API)의 성능을 테스트할 수 있습니다.

대상 파일을 만들고 텍스트 편집기에서 엽니다.
nano target.list

복사
여기에 다른 엔드포인트를 넣습니다.
GET http://<application_url>/list/user/1
GET http://<application_url>/list/user/2
GET http://<application_url>/list/user/3

복사
파일에 정의하거나 명령하는 POST것도 가능합니다 .PUT

POST http://<application_url>/create/newuser/
Content-Type: application/json
@/path/to/newuser.json

복사
파일 내용에는 /path/to/newuser.json요청 본문이 포함되어 있습니다.

{
  "name": "Peter";
  "lastname": "Smith";
  "email": "psmith@example.com"
}

복사
Vegeta 실행, -duration플래그는 공격 기간을 지정하고 -rate플래그는 시간 단위당 요청 수를 
정의합니다(기본값은 50/1s로 설정됨).
vegeta attack -duration=5s -rate=5 -targets=target.list

복사
보고서 생성
-output 매개 변수를 사용하여 출력 파일에 저장할 수 있는 데이터를 수집하기 위해 실행되는 
모든 부하 테스트.

각 부하 테스트 중에 수집된 데이터는 출력 파일에 저장됩니다.

Vegeta에서 공격을 실행합니다. 출력 파일의 기본 파일 이름은 results.bin. 다음 플래그를 
사용하여 이름을 지정할 수 있습니다 -output.
vegeta attack -duration=120s -rate=100 -targets=target.list -output=attack-5.bin

복사
명령 을 사용하여 HTML 보고서 및 플롯을 생성합니다 vegeta plot. 플래그 -title를 사용하면 
플롯의 제목을 지정할 수 있습니다.
vegeta plot -title=Attack%20Results attack-5.bin > results.html

복사
플롯을 보려면 웹 브라우저에서 HTML 파일을 엽니다.



또는 보고서를 JSON 출력으로 생성할 수도 있습니다.
vegeta report -type=json results.bin

복사
다음과 같이 JSON 출력을 반환합니다.

{
  "latencies":{
      "total":5018316104,
      "mean":418193,
      "50th":393268,
      "95th":523664,
      "99th":737809,
      "max":13479790
  },
  "bytes_in":{
      "total":7344000,
      "mean":612
  },
  "bytes_out":{
      "total":0,
      "mean":0
  },
  "earliest":"2019-05-23T15:14:25.216411448+02:00",
  "latest":"2019-05-23T15:16:25.206316941+02:00",
  "end":"2019-05-23T15:16:25.206710805+02:00",
  "duration":119989905493,
  "wait":393864,
  "requests":12000,
  "rate":100.00841279685865,
  "success":1,
  "status_codes":{
      "200":12000
  },
  "errors":[
  ]
}

복사
터미널에서 직접 보고서를 보려면 다음을 실행하십시오.
vegeta report results.bin

복사
첫 번째 단계에서 본 형식으로 보고서를 제공합니다.

Requests      [total, rate]            12000, 100.01
Duration      [total, attack, wait]    1m59.990299357s, 1m59.989905493s, 393.864µs
Latencies     [mean, 50, 95, 99, max]  418.193µs, 393.268µs, 523.664µs, 737.809µs, 
13.47979ms
Bytes In      [total, mean]            7344000, 612.00
Bytes Out     [total, mean]            0, 0.00
Success       [ratio]                  100.00%
Status Codes  [code:count]             200:12000
Error Set:

복사
Vegeta에 대한 자세한 내용은공식 문서.

https://github.com/tsenart/vegeta/blob/master/README.md

 

참고 테스트 

베지타 테스트 

echo "GET http://nsm-dev-mfo.nsmall.com/" | vegeta attack -duration=5s | vegeta report -type=json > result.json


echo "GET http://nsm-dev-mfo.nsmall.com/" | vegeta attack -duration=5s | vegeta report -type='hist[0, 2ms, 4ms, 6ms, 8ms, 10ms]'

 echo "GET http://nsm-dev-mfo.nsmall.com/" | vegeta attack -duration=5s | vegeta report

  vegeta attack -rate=1 -duration=5s -targets=targets.txt | vegeta report 

  targets.txt

GET http://nsm-dev-mfo.nsmall.com/
POST http://nsm-dev-mfo.nsmall.com/
X-Account-ID: 99
# Can make comment
@./post.json


{
  "hello": "world",
  "안녕": "테스트"
}

$ vegeta attack -name=50qps -rate=50 -duration=5s -targets=targets.txt > results.50qps.bin
$ cat results.50qps.bin | vegeta plot > plot.50qps.html

plot.50qps.html
0.38MB

댓글