概要
Artilleryという負荷ツールを使って、シーケンシャルな入力値をPostする負荷テストを実現する設定を説明する
Artilleryとは
簡易的な負荷テストはApache benchが有名だが、ちょっと複雑なテストするツールとしてartilleryが便利だ。古くからあるjMaterよりも軽量でモダンな感じもする。
動作環境
» artillery --version
___ __ _ ____ _
_____/ | _____/ /_(_) / /__ _______ __ (_)___ _____
/____/ /| | / ___/ __/ / / / _ \/ ___/ / / / / / __ \/____/
/____/ ___ |/ / / /_/ / / / __/ / / /_/ / / / /_/ /____/
/_/ |_/_/ \__/_/_/_/\___/_/ \__, (_)_/\____/
/____/
------------ Version Info ------------
Artillery: 1.6.0
Artillery Pro: not installed (https://artillery.io/pro)
Node.js: v13.7.0
OS: darwin/x64
--------------------------------------
入力データ用のCSV
入力値を定義したCSVファイをを用意する
この例では、連続的なIDと日付の文字列をそれぞれid, dateとした
keywords.csv
id,date
1,2020/1/1
2,2020/1/2
3,2020/1/3
4,2020/1/4
5,2020/1/5
6,2020/1/6
7,2020/1/7
8,2020/1/8
9,2020/1/9
10,2020/1/10
11,2020/1/11
負荷テスト定義ファイル
script.yml
config:
target: "https://テスト先のURL"
phases:
- duration: 5
arrivalRate: 2
# CSVを読み込ませる場合はpayload要素を追加する
payload:
# 対処のファイルと読み込むフィールドの定義
path: "keywords.csv"
fields:
- "id"
- "date"
# csvの頭から順番に実行したい場合はシーケンシャルを指定する
order: sequence
# csvの1行目を無視する
skipHeader: true
scenarios:
- name: "シナリオ名"
flow:
- post:
url: "/"
# Postする際にパラメタを{{xxx}}で定義する
json:
id: "{{id}}"
date: "{{date}}"
テストの実行
artilleryのパスが通っている場合はこのようにrunとテスト定義ファイルを引数につけてやる
artillery run script.yml
結果の例
All virtual users finished
Summary report @ 17:31:08(+0900) 2020-05-22
Scenarios launched: 10
Scenarios completed: 10
Requests completed: 10
Mean response/sec: 1.67
Response time (msec):
min: 994.1
max: 2057.4
median: 1074.3
p95: 2057.4
p99: 2057.4
Scenario counts:
Search and buy: 10 (100%)
Codes:
200: 10