nodejs와 artillery를 이용한 성능 테스트 환경구성과 간단하게 테스트 해볼 수 있는 예제를 준비하였습니다.
1. nodejs 공식 사이트(https://nodejs.org/ko/) 에서 환경에 맞는 버전을 설치한다
2. 개발 툴 VSCode 설치(https://code.visualstudio.com/)한다
3. 테스트할 폴더 생성 후 해당 폴더에서 VSCode 실행한다.
예) D:\testfolder
4. VSCode - Terminal - New Terminal 실행
아래 명령어 입력하여 artillery 설치한다.
$ npm install -g artillery
- 버전 확인
$ artillery version
Telemetry is on. Learn more: https://artillery.io/docs/resources/core/telemetry.html
___ __ _ ____
_____/ | _____/ /_(_) / /__ _______ __ ___
/____/ /| | / ___/ __/ / / / _ \/ ___/ / / /____/
/____/ ___ |/ / / /_/ / / / __/ / / /_/ /____/
/_/ |_/_/ \__/_/_/_/\___/_/ \__ /
/____/
....
5. testscenarios.yml 파일을 생성하고 아래 스크립트 파일을 참고 하여 시나리오를 작성한다
예) D:\testfolder\testscenarios.yml
config:
target: "[TEST API URI주소]" # ex) https://testapi.dev.com
phases:
- duration: 60 # Test for 60 seconds
arrivalRate: 10 # Every second, add 10 users
rampTo: 100 # And keep it steady at 100 users
payload:
path : "[데이터 가져올 파일 PATH 지정].csv" # ex) ./testfile.csv
fields :
- "id" # 변수명 지정
scenarios:
- flow:
- post:
url: "[TEST API URI 상세주소]" # ex) /user/{{ id }}
headers:
x-api-key: "{{ id }}" # 위에서 정의한 변수명 지정 {{ 변수명 }}
json:
id: "{{ id }}"
os_type: "1"
- 추가설명
config.phases:
- duration: 60 # 60초 동안
arrivalRate: 10 # 매 초 10명의 유저가 호출
rampTo: 100 # payload한 100명의 유저가 유지 됨
6. report 폴더 생성
D:\testfolder\report
7. artillery 실행
- artillery run --output [테이트 결과를 저장할 파일 path] [테스트 스크립트 path]
$ artillery run --output ./report/testoutput.json testscenarios.yaml
8. 위에서 생성한 테스트한 결과물(testoutput.json)을 리포트 html 형태로 볼 수 있다
#리포트 생성
$ artillery report ./report/testoutput.json
<참고>