DEV Community

Theo
Theo

Posted on

Quick LoadTests with Artillery

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
Enter fullscreen mode Exit fullscreen mode

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"
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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.

https://artillery.io/docs/getting-started

Top comments (2)

Collapse
 
valentinepalazkov profile image
Valentine Palazkov • Edited

OK,

Probably it's a dumb question: how to run that pretty strange command line?

I am talking about this:

DEBUG=http artillery run load.yml
Enter fullscreen mode Exit fullscreen mode

I have windows 10 and it fails on "DEBUG=http" with the reason:

'DEBUG' is not recognized as an internal or external command,
operable program or batch file.
Enter fullscreen mode Exit fullscreen mode
Collapse
 
tios profile image
Theo

DEBUG=http sets environment variable. In Windows you should do 'set DEBUG=http...'

Sorry for the very late response.