Skip to main content

Artillery Performance Testing

Artillery is a modern, powerful, and easy-to-use performance testing toolkit. It allows you to generate load on your systems and provides detailed insights into performance metrics. Artillery supports testing APIs, web applications, and microservices, and integrates well with continuous integration pipelines.

Installing Artillery

Artillery is a Node.js-based tool, so you need to have Node.js installed on your system. You can install Artillery using npm, the Node.js package manager.

Installation Steps

  1. Install Node.js

    If you don't have Node.js installed, you can download and install it from Node.js official website. You can also use a version manager like nvm (Node Version Manager) for easier management.

  2. Install Artillery

    Once Node.js is installed, you can install Artillery globally using npm:

    npm install -g artillery

Creating and Running Artillery Tests

Artillery uses a YAML or JSON configuration file to define your load tests. Here’s how you can set up and execute your performance tests.

Basic Usage Create a Test Script

Create a YAML or JSON file to define your test. Here’s a basic example in YAML:

# test-script.yml
config:
target: 'https://your-api-endpoint.com'
phases:
- duration: 60
arrivalRate: 5

scenarios:
- flow:
- get:
url: "/"

This script configures Artillery to send 5 requests per second to the root URL of your API for 60 seconds.

artillery run test-script.yml

Example Test Scripts

Here are a few example test scripts to illustrate different scenarios.

Example Script 1: Simple HTTP Load Test

# simple-load-test.yml
config:
target: 'https://your-api-endpoint.com'
phases:
- duration: 30
arrivalRate: 10

scenarios:
- flow:
- get:
url: "/api/resource"

Description: Sends 10 requests per second to /api/resource for 30 seconds.

Example Script 2: Load Test with Custom Headers

# custom-headers.yml
config:
target: 'https://your-api-endpoint.com'
phases:
- duration: 60
arrivalRate: 20

scenarios:
- flow:
- get:
url: "/api/data"
headers:
Authorization: "Bearer your-token"

Description: Sends 20 requests per second to /api/data with a custom Authorization header for 60 seconds.

Example Script 3: Complex Scenario with Multiple Requests

# complex-scenario.yml
config:
target: 'https://your-api-endpoint.com'
phases:
- duration: 120
arrivalRate: 15

scenarios:
- flow:
- get:
url: "/api/login"
headers:
Content-Type: "application/json"
json:
username: "testuser"
password: "password123"
- get:
url: "/api/profile"
headers:
Authorization: "Bearer your-token"

Description: Logs in a user by sending a POST request to /api/login and then sends a GET request to /api/profile for 120 seconds with 15 requests per second.

Advanced Features

Customizing Test Outputs Artillery can produce detailed reports and integrate with other tools for in-depth analysis.

JSON Output:

artillery run test-script.yml --output report.json

HTML Reports:

Convert the JSON output into an HTML report:

artillery report --output report.html report.json

Monitoring and Analysis

Artillery integrates with various monitoring tools for enhanced performance analysis:

Grafana and InfluxDB: Use Artillery with Grafana and InfluxDB for real-time monitoring and visualization of test metrics.

Artillery is a powerful and flexible performance testing tool that helps you ensure the reliability and performance of your systems. By following this guide, you can set up and execute performance tests, generate detailed reports, and integrate testing into your development workflow effectively.