Artillery
What is Artillery?
Load testing, one of many valuable testing methods you can use before release to ensure that your application is bug-free and runs seamlessly. The main process of load testing is, whether an application can withstand the load of concurrent users, requests, and data volumes when in use.
Artillery is a modern, powerful & easy-to-use load testing and functional testing toolkit. Use it to ship scalable applications that stay performant & resilient under high load.
Artillery is written in Node.js (but you don’t need to know Node.js or JS to use Artillery)
Why Artillery?
- Supports multiple protocols- HTTP(S), WebSockets and socket.io
- Software preferred by e-commerce backends, IoT backends and transactional APIs.
- Artillery is open source under MPLv2, which is an OSI-approved, permissive and non-viral license.
- We can see response times/latency percentiles, requests per second, concurrency, throughput, or track custom application-specific metrics with a tiny bit of Javascript code.
How to install Artillery?
Firstly, we have to install Node.js higher than 8.6.0 versions.
You can install the latest version with this command:
nvm install –latest-npmNow you can install the Artillery with this command:
npm install -g artilleryHow to use Artillery?
Artillery allows users to run custom test scripts written in either yaml or json, users can also perform a quick test without loading external scripts. The following command specifies 20 GET requests to be sent every 10 second creating 10 virtual users per request.
artillery quick –count 10 -n 20 https://your-local-site-to-be.tested This quick command can be useful for very simple tests only. Now lets see how can we run a test.yml and get the load testing result.In this script, we specify that we are testing a service running on https://your-website-link which will be talking to over HTTP. Scenarios are actions that the users would be performing within the website e.g searching, carting items, registration etc.
Scenarios are written in the configuration file which is used to run a custom test. artillery.io also allows users to specify a file from which values can be imported to be used in a scenario. We define one load phase, which will last 10 second with 10 new virtual users, arriving every second (on average). We capture the response using regular expression and stores it in a variable response. The response is logged using -log at the end.
We can now run the above yamls file using the following command.
artillery run test.yml
Reading Artillery Response
Artillery provides feedback for each requests sen which look something like :A range of different statistic are displayed in the response including the number of requests, a latency report for each request, duration of each scenario ran and any HTTP status codes returned from the response. The response is printed every 10 seconds by default and a final response is then printed after the test has been completed with an aggregate statistic of all the tests ran.
Request latency and scenario duration are recorded in milliseconds, p95 and p99 values represent 95th and 99th percentile values. NaN is returned if there are not enough responses received to perform the calculation.
If there are any errors (such as socket timeouts), those will be printed under Errors in the report as well.
Publishing metrics to external monitoring system
If you want to send Artillery metrics (such as latency and response codes) to an external monitoring system, you can use the official artillery-publish-metrics plugin.
Some support targets :
- Datadog
- StatsD
- InfluxDB with Telegraph + StatsD plugin