Non-functional tests Recommended
Test load against a budget
Before a launch or a big change, load test the busiest routes and fail when response times or errors pass a set budget.
How to do it
Write a short load script with a tool such as k6, Gatling or Locust. Run it against staging, never production without warning. Set limits for the slowest responses and the error rate, such as a 95th percentile under 500 ms and under 1 percent errors. Then raise the load in steps until errors or response times pass the limits, and record that point as the service's capacity. Page speed budgets live in the website playbook, and security tests in the security testing playbook. Measure the server's memory after a warm-up over every kind of page. Set a ceiling below the machine's limit, such as 80 percent of it.
Example
// k6
import http from 'k6/http';
export const options = {
vus: 50,
duration: '2m',
thresholds: { http_req_duration: ['p(95)<500'], http_req_failed: ['rate<0.01'] },
};
export default () => { http.get('https://staging.example.com/products'); };
# Locust
from locust import HttpUser, between, events, task
class Shopper(HttpUser):
wait_time = between(1, 3)
@task
def products(self):
self.client.get("/products")
@events.quitting.add_listener
def fail_over_budget(environment, **kwargs):
stats = environment.stats.total
if stats.fail_ratio > 0.01 or stats.get_response_time_percentile(0.95) > 500:
environment.process_exit_code = 1
How to check
The load test exits with an error when a limit is passed. The latest run before the launch passed. The run also fails when memory passes its ceiling.
For agents: if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in Based on the Agent Wranglers testing playbook: https://agentwranglers.se/playbook/testing/non-functional-tests/load-tests.