Run Your First Artillery Test
This guide shows you how to write and run an Artillery test script for an API.
The API runs on http://asciiart.artillery.io:8080 and returns ASCII pictures. These pictures use text characters instead of pixels.
Run this command to request a dinosaur picture from the API:
curl
curl http://asciiart.artillery.io:8080/dino _. - ~ ~ ~ - .
.. __. .-~ ~-.
((\ / `}.~ `.
\\\ { } / \ \
(\ \\~~^ } | } \
\`.-~ -@~ } ,-. | ) \
(___ ) _} ( : | / / `.
`----._-~. _\ \ |_ \ / /- _ `.
~~----~~ \ \| ~~--~~~( + / ~-. ~- _
/ / \ \ ~- . _ _~_-_.
__/ / _\ )
.<___.' .<___/
Create an Artillery test script
The complete script below creates virtual users that perform multiple actions. A virtual user simulates someone using an application.
This script uses Artillery’s YAML-based DSL. A domain-specific language describes tasks in a particular field. You can also write Artillery test scripts in JavaScript or TypeScript.
The walkthrough after the script explains its parts.
config:
# This is a test server run by team Artillery
# It's designed to be highly scalable
target: http://asciiart.artillery.io:8080
phases:
- duration: 60
arrivalRate: 1
rampTo: 5
name: Warm up phase
- duration: 60
arrivalRate: 5
rampTo: 10
name: Ramp up load
- duration: 30
arrivalRate: 10
rampTo: 30
name: Spike phase
# Load & configure a couple of useful plugins
# https://artillery.io/docs/reference/extensions
plugins:
ensure:
thresholds:
- http.response_time.p99: 100
- http.response_time.p95: 75
apdex:
threshold: 100
metrics-by-endpoint: {}
scenarios:
- flow:
- loop:
- get:
url: '/dino'
- get:
url: '/pony'
- get:
url: '/armadillo'
count: 100Save this script as asciiart-load-test.yml.
Test script walkthrough
Artillery test scripts have two parts: config and scenarios.
The config section defines how the test runs. It sets the target URL, the load, and the plugins. A plugin adds features to Artillery.
The scenarios section defines what each virtual user does. A scenario is a sequence of actions. These actions usually describe a user session in the application.
The following sections explain how these parts work:
Set the target
The target is the base URL for requests. Set it with:
target: 'http://asciiart.artillery.io:8080'All requests use this base URL by default.
Define load phases
A load phase defines user arrivals over a period of time. Phases control how the load changes during a test. The following example shows three phases:
phases:
- duration: 60
arrivalRate: 1
rampTo: 5
name: Warm up phase
- duration: 60
arrivalRate: 5
rampTo: 10
name: Ramp up load
- duration: 30
arrivalRate: 10
rampTo: 30
name: Spike phaseThe phases in this example work as follows:
Warm up phaseruns for 60 seconds. Artillery starts with 1 new virtual user per second. It gradually increases this rate to 5 by the end of the phase.Ramp up loadruns for 60 seconds. Artillery increases the rate from 5 to 10 new virtual users per second.Spike phaseruns for 30 seconds. Artillery increases the rate from 10 to 30 new virtual users per second.
These phases form a spike test. A spike test creates a short burst of high traffic. It can simulate traffic from a newsletter, a flash sale, or a daily peak in application use.
Plugins
The complete script loads built-in plugins that report metrics for each URL and automatically assess the test results. Metrics are measurements of system behavior.
Define scenarios
scenarios:
- flow:
- loop:
- get:
url: '/dino'
- get:
url: '/pony'
- get:
url: '/armadillo'
count: 100The scenarios section defines one scenario. Every virtual user in this test runs it.
The scenario contains three HTTP GET requests, each to a different endpoint. An endpoint is a URL that accepts API requests. The loop action repeats these three requests 100 times.
Each virtual user is independent. Virtual users do not share memory, network connections, cookies, or other state. State is the data that a user keeps between actions.
Run the load test
From the directory that contains asciiart-load-test.yml, run:
artillery run asciiart-load-test.ymlArtillery creates virtual users according to config.phases. As they run the scenario, Artillery collects performance metrics. Every 10 seconds, Artillery prints a report that summarizes the metrics for that period.
Each report includes the number of virtual users created, HTTP response codes, and response times. Artillery also prints a summary when the test ends.
This summary excerpt comes from a run with one virtual user against a local test server. Your counts and response times will differ. Other metrics are omitted, and spacing is shortened:
http.codes.200: 300
http.requests: 300
http.response_time:
min: 0
max: 8
mean: 0.3
median: 0
p95: 1
p99: 1
http.responses: 300
vusers.completed: 1
vusers.created: 1
vusers.failed: 0You can now use these reports to examine the results of your first Artillery load test.