Back to Top

Artillery HTTP load testing

Updated 16 July 2021

Artillery is a simple but powerful load testing toolkit. It can be used to make application perform better under high load. We write our load testing scripts in YAML and tell Artillery to run them. The main purpose is to simulate realistic load on complex applications, and as such it works with the concepts of virtual users, that arrive to use the application in phases. Now let’s have a look to add HTTP load on an application.
When we say HTTP request,  it’s object may have the following attributes:

  • url – the request URL; it will be appended to the target
  • json – a JSON object to be sent in request body
  • body – arbitrary data to be sent in request body
  • headers – a JSON object describing header key-value pairs
  • cookie – a JSON object describing cookie key-value pairs
  • capture – used to capture values from the response body of a request and store those in variables

The following example covers most of the use cases in artillery YAML script

testHttp.yaml :

    - duration: 10
      arrivalRate: 10
    # Responses have to be sent within 5 seconds or the request will be aborted
    timeout: 5
      # path is relative to the location of the test script
    path: "../../file/loadInput.csv"
      - "shop"
      - "customerId"
    order: "sequence"
  processor: "../../assets/js/count.js"  
  - flow:
      - function: "setBidCount"
      - loop:
          - get:
              # the value of count comes from a JavaScript function 'setCount' declared in count.js   
              url: "/{{ shop }}/{{ customerId }}/{{ count }}"
              # capturing responce using reg expression
                - regexp: "[^]*"
                  as: "msg"
          - log: "msg= {{msg}}"
        count: 20

loadInput.csv :,112,113,115,118

count.js :

Start your headless eCommerce
Find out More
'use strict';

module.exports = {
  setCount: setCount

var i= 505;

function setCount(context, events, done) {
  i= i+1;
  context.vars.count = i;
  return done();

If a response takes longer than 5 seconds Artillery will abort the request and report an ETIMEDOUT error. To set different timeout, we change config.http.timeout to a number.
Debug messages are logged with the log action, and log can include variables too( log: “msg= {{msg}}”).We use the loop construct to loop through a number of requests in a scenario. For example, each virtual user will send 10 GET requests to specified url with given scenarios.

In some cases it is useful to inject data from external files into test scenarios. Payload files are in CSV format and Artillery allows mapping of the rows to a variable name that can be used in scenario definitions. Here the values of variables {{ shop }} and {{ customerId }}are extracted form the csv file named  loadInput.csv. Rows from the CSV file are picked at random by default, if we want to make them in order we state order: “sequence”.

The test scripts may include custom JS via config.processor attribute in your test script. Here, count.js is included and the function “setBidCount” is called under the scenarios. The function under count.js returns a no starting from 501. We can set the function according to the needs and the functionality we want to achieve. To run the above script, refer here.

Suggestion are highly appreciated in the comments 😀

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*

Be the first to comment.

Back to Top

Message Sent!

If you have more details or questions, you can reply to the received confirmation email.

Back to Home