Artillery runs performance tests against backend services. A test definition has two main parts: configuration and one or more scenarios (Virtual Users Actions (GET, POST)). duration of a test is not the combined duration of all of its load phases, but the amount of time it takes for all virtual users created in those load phases to finish their scenarios.
Installation:
npm install -g artillery artillery dino
Run
artillery run loadtest.yaml
loadtest.yaml
emulate a new user arriving at the application every second, for 5 seconds
config: target: "http://localhost:3000" phases: - duration: 5 arrivalRate: 1 scenarios:
- flow:
- get: url: "/slow"
- get: url: "/fast" =============================
Another more complete example
config: target: "http://localhost:3600" phases: # Every 5 sec 1 user arrives for 60s - duration: 10 arrivalRate: 5 name: Warm up # Every 5 sec 50 users arrives for 120s - duration: 10 arrivalRate: 5 rampTo: 50 name: Ramp up load # Every 50 sec 50 users arrives for 120s - duration: 10 arrivalRate: 50 name: Sustained load payload: # Load search keywords from an external CSV file and make them available # to virtual user scenarios as variable "keywords": path: "keywords.csv" fields: - "keywords" scenarios:
We define another scenario:
- name: "Healthcheck"
flow:
- get: url: "/health"
Pause for 3 seconds:
- think: 3
Add product to cart:
- post: url: "/cart" json: productId: "{{ id }}"
We define one scenario:
- name: "Search and buy"
flow:
- post:
url: "/search"
body: "kw={{ keywords }}"
The endpoint responds with JSON, which we parse and extract a field from
to use in the next request:
capture: json: "$.results[0].id" as: "id"
Get the details of the product:
- get: url: "/product/{{ id }}/details"
Pause for 3 seconds:
- think: 3
Add product to cart:
- post: url: "/cart" json: productId: "{{ id }}"
- post:
url: "/search"
body: "kw={{ keywords }}"
Created on 2/5/2021