Stress testing with Artillery

To ensure a server can handle a certain amount of requests per second for a certain delay, we can use stress testing.

Artillery is a library for stress testing. We define scenarios in a YAML file and how we want to simulate users making requests accord to scenarios. Here is an example of configuration for a chat application:

yaml
# chat.yaml
config:
target: "http://localhost:3333"
phases:
# Create up to 10 virtual users per second in one minute
- duration: 60
arrivalRate: 10
# Create up to 100 virtual users per second in ten minutes
- duration: 600
arrivalRate: 100
scenarios:
# Enable sending Socket.io events
- engine: "socketio"
flow:
# Create a user
- post:
url: "/sign-up"
json:
username: "Jean-Louis Murat"
password: "La Princesse of the Cool"
# Get my information
- get:
url: "/me"
# Add a friend
- post:
url: "/friend"
json:
id: "b0518bea-4df4-415c-a01d-129ecae34c33"
# Send a message to my friend
# HTTP requests and Socket.io events can be mixed!
- emit:
channel: "chat"
data:
userId: "b0518bea-4df4-415c-a01d-129ecae34c33"
message: "Hello JL!"

Join my mailing list

Get monthly insights, personal stories, and in-depth information about what I find helpful in web development as a freelancer.

Email advice once a month + Free XState report + Free course on XState

Want to see what it looks like? View the previous issues.

I value your privacy and will never share your email address.