Prompt
How can I run performance tests on REST APIs?
Latest observation
Nov 10, 2026
OpenAI APIWeb search: off
To run performance tests on REST APIs, you usually want to measure things like response time, throughput, error rate, and behavior under load. A good approach is:
1) Define what you want to test
Common test types:
- Load testing: expected normal/peak traffic
- Stress testing: push until failure
- Spike testing: sudden traffic bursts
- Soak/endurance testing: sustained load over time
- Baseline testing: establish normal performance for comparison
2) Pick a tool
Popular tools for REST API performance testing:
- k6 (modern, scriptable, great for CI/CD)
- JMeter (widely used, GUI-based)
- Locust (Python-based, flexible)
- Gatling (Scala-based, high performance)
- Postman + Newman for basic scripted runs, though not ideal for heavy load
3) Create realistic test scenarios
Include:
- Authentication/login flow
- Common GET/POST/PUT/DELETE requests
- Mixed read/write ratios
- Realistic user behavior and payload sizes
- Think time / pacing if simulating real users
4) Set up your test environment
- Use a staging environment similar to production
- Ensure monitoring is enabled:
- CPU, memory, disk, network
- DB performance
- App logs
- APM tools like Datadog, New Relic, Prometheus/Grafana, etc.
- Avoid testing against production unless carefully planned and approved
5) Define metrics and pass/fail criteria
Track:
- Latency: p50, p95, p99
- Throughput: requests/sec
- Error rate
- Resource utilization
- Saturation points
Example acceptance criteria:
- p95 latency < 300 ms
- error rate < 1%
- supports 500 RPS for 30 minutes
6) Run the test with increasing load
Typical pattern:
- Start small
- Ramp up users/requests gradually
- Hold steady at target load
- Increase beyond expected load if needed
- Record results at each stage
7) Analyze bottlenecks
Check for:
- Slow database queries
- N+1 query problems
- Lock contention
- Thread pool exhaustion
- Cache misses
- External dependency latency
- Insufficient connection pooling
Example with k6
import http from 'k6/http';
import { check, sleep } from 'k6';
export const options = {
stages: [
{ duration: '1m', target: 50 },
{ duration: '3m', target: 50 },
{ duration: '1m', target: 200 },
{ duration: '3m', target: 200 },
{ duration: '1m', target: 0 },
],
};
export default function () {
const res = http.get('https://api.example.com/v1/items');
check(res, {
'status is 200': (r) => r.status === 200,
'latency < 300ms': (r) => r.timings.duration < 300,
});
sleep(1);
}
Run it:
k6 run script.js
8) Automate it
Integrate performance tests into CI/CD:
- Run smoke performance tests on every build
- Run full load tests nightly or before release
- Compare results against previous runs to detect regressions
9) Report results
Include:
- Test setup
- Load pattern
- Metrics
- Bottlenecks found
- Recommendations for optimization
If you want, I can also give you:
- a JMeter example
- a k6 script for your API
- a step-by-step test plan
- or help you choose the best tool for your stack