Some APIs you develop will have strict performance requirements.
With integrated API Statistics and a mass API test tool you can discover potential bottlenecks within your business logic, database indexes, and even Application Infrastructure.
Performance testing is similar to manual testing, with a key difference of using a tool to call your API in mass and under difference scenarios.
Load testing and stress testing are other types of tests you perform to find the benchmarks of your Application Infrastructure.
A useful tool for stress testing and determining benchmarks is Artillery, which allows mass calling of your APIs along with configurable scenarios.
Artillery is a free node package that you install on your local computer like this:
- npm install -g artillery
It can be used in a variety ways. Here are a couple quick ways to use it from a terminal:
- artillery quick --count 20 --num 100 http://pjsserver/wsapi/customers/103
This will start 20 connections (sessions), and on each connection it will call your API 100 times, 1 at a time.
This is a good example for performance testing, and can tell you the overall throughput of your API
- artillery quick --rate 20 --duration 60 http://pjsserver/wsapi/customers/103
This will run for a for 60 seconds, each second 20 API calls are attempted
This is good example for load or stress testing, and can tell you how well this API will stand up under pressure.
The Artillery output provides metrics on these tests which include:
- Scenarios launched and completed
- Response times in different forms: min, max, mean, median, top 95 and 99 percentiles
- Response status codes
With the mass tests running or finished, you can take a look at the API statistics:
- Navigate to the Profound.js IDE
- Open the API file
- At the bottom right, change to the Stats tab
To view all of your API globally, you can use the API Dashboard, it includes all of this plus much more.
On the top-right corner of this tab, there are refresh buttons, refresh now, auto-refresh paused, auto-refresh every 1 second, 10 seconds, 30 seconds and every minute.
These statistics are collected automatically through the Profound.js service.
Below is an example of API file customer.api.json file, with the Get one customers API selected.
From this test view, you can see a lot of information. Some of the more important information:
- Request - This is the total requests
- Errors - This is the total errors
- Average Handle Time - Average time the server took to respond to each request over the last hour
- Handle Time histogram - This will show how this API has been responding over the last hour
- Overall Req rate - This number can be misunderstood. The calculation is based on the start of the Profound.js service
- Overall Err rate - This number can be misunderstood. The calculation is based on the start of the Profound.js service