Quick LoadTests with Artillery
Theo
Posted on May 13, 2020
I was troubleshooting a capacity issue with one of the web application and wanted to reproduce why some calls were failing. Usually I turn to Jmeter but today I decided to use something quick and fast and found this nifty nodejs called Artillery. Just configure what you wanted to do in a yml file and run the test. You will get report of the http responses and various other stats.
I found it very useful to make a quick number of requests along with request chaining and authentication. Here is what I did.
To install
yarn add global artillery
Now create a yml file as below
config:
target: 'https://api.edge.service'
phases:
- duration: 30
arrivalRate: 1
scenarios:
- flow:
- log: "Getting token"
- post:
url: "/token"
json:
username: 'xxxxxx'
password: 'xxxxxxxx'
grant_type: 'password'
capture:
json: "$.access_token"
as: access_token
expect:
- statusCode: 200
- get:
headers:
Authorization: 'Bearer {{ access_token }}'
url: "/apis/users/v1"
The above yml is self explanatory. But in brief, here is what it does, it has a base url of 'https://api.edge.service' and the test will run for 30 seconds with 1 user request being made every second. It will first make a token request and uses the 'access_token' field in the response json in the next request's 'Authorization' header.
So there you have it, a request which first gets an authentication token and then using that token to make another API call.
Run the test
# With debug to see the requests made.
DEBUG=http artillery run load.yml
# With debug to see the requests and responses made.
DEBUG=http:response artillery run load.yml
# With debug to see the requests and responses made.
DEBUG=http:response artillery run load.yml
#Or just run in default mode
artillery run load-dev.yml
The Report
Summary report @ 17:20:54(-0400) 2020-05-13
Scenarios launched: 1
Scenarios completed: 1
Requests completed: 2
Mean response/sec: 1.35
Response time (msec):
min: 45.5
max: 1126.6
median: 586.1
p95: 1126.6
p99: 1126.6
Scenario counts:
0: 1 (100%)
Codes:
200: 2
The more I read the documentation of Artillery, the more I like it. It also has a PRO version which is paid and can be run from cloud. For me, I just use it my local to run some quick tests.
Posted on May 13, 2020
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.