.http files you use for functional tests can drive load tests. This tutorial covers rate-based testing, virtual user mode, multi-phase profiles, and threshold-based pass/fail.
Prerequisites
- hitspec installed (Installation)
- A test file to stress test (see Basic CRUD)
Quick Start
The simplest way to stress test is with CLI flags:api.http.
Run a rate-based stress test
Rate mode sends a fixed number of requests per second:This runs for 1 minute at 20 requests per second. hitspec distributes the load across all requests in the file.Output:
Run a virtual user stress test
VU mode simulates concurrent users, each sending requests sequentially:This creates 10 virtual users, each waiting 500ms between requests. Unlike rate mode, VU mode models real user behavior where each user completes a request before starting the next.
Add ramp-up
Ramp up gradually to avoid overwhelming the server at startup:The rate increases linearly from 0 to 50 rps over the first 30 seconds, then holds at 50 for the remaining 90 seconds.
Set pass/fail thresholds
Thresholds let you define success criteria. The test exits with code 1 if any threshold is violated:Available threshold metrics:
Combine multiple thresholds with commas.
| Metric | Operator | Example | Description |
|---|---|---|---|
p50 | <, <= | p50<100ms | 50th percentile latency |
p95 | <, <= | p95<200ms | 95th percentile latency |
p99 | <, <= | p99<500ms | 99th percentile latency |
max | <, <= | max<1s | Maximum latency |
errors | <, <= | errors<1% | Error rate percentage |
rps | >, >= | rps>50 | Minimum requests per second |
Configuration File
For repeatable stress test configurations, define profiles inhitspec.yaml.
Rate-based Profile
hitspec.yaml
Virtual User Profile
hitspec.yaml
Profile Strategies
Smoke Test
Verify the system handles minimal load without errors. Run this on every deploy.Load Test
Sustained normal traffic levels. Verify performance under expected conditions.Stress Test
Push beyond normal limits to find the breaking point.Spike Test
Sudden traffic surge to test auto-scaling and recovery.Per-Request Configuration
You can control how individual requests participate in stress tests using metadata:| Directive | Description |
|---|---|
@stress.weight N | Relative frequency (default 1). A weight of 3 means 3x more requests. |
@stress.think N | Think time in ms after this request (VU mode). |
@stress.skip | Exclude this request from stress testing. |
@stress.setup | Run once before the stress test starts. |
@stress.teardown | Run once after the stress test ends. |
Stress Testing in CI
Combine stress profiles with the GitHub Action for automated performance gates:.github/workflows/stress.yml