Prompt
How can I run performance tests on REST APIs?
Latest observation
Oct 6, 2026
OpenAI APIWeb search: off
To run performance tests on REST APIs, you usually simulate realistic traffic and measure how the API behaves under load. Here’s a practical approach:
1. Define what you want to measure
Common performance goals:
- Response time / latency: how fast endpoints respond
- Throughput: requests per second
- Error rate: 4xx/5xx under load
- Scalability: how the API behaves as traffic increases
- Stability: whether performance degrades over time
2. Choose a performance testing tool
Popular tools for REST APIs:
- k6 – modern, scriptable, easy to integrate with CI/CD
- JMeter – widely used, GUI-based
- Gatling – good for high-load testing, Scala-based
- Locust – Python-based, flexible
- Postman/Newman – okay for basic functional checks, not ideal for load testing
3. Design test scenarios
Create realistic API usage patterns:
- Login/authentication
- Read-heavy endpoints
- Create/update/delete operations
- Mixed workflows
- Different user roles or request payload sizes
Typical test types:
- Smoke test: verify the script works with a small number of requests
- Load test: expected normal production traffic
- Stress test: push beyond normal traffic to find breaking point
- Spike test: sudden traffic surge
- Soak test: sustained load over time to find memory leaks or degradation
4. Prepare test data and environment
- Use a staging environment close to production
- Ensure databases, caches, and third-party dependencies are representative
- Use realistic test data
- Reset or isolate data if tests modify state
- Make sure rate limits, auth, and monitoring are configured correctly
5. Create the test script
Your script should:
- Authenticate if needed
- Send requests with realistic headers/body
- Include think time/pacing if applicable
- Validate response codes and key response fields
- Parameterize data to avoid cache-only behavior
6. Run the test with different load levels
Example load progression:
- 10 virtual users
- 50 virtual users
- 100 virtual users
- 500 virtual users
- Observe latency, errors, and system metrics at each stage
Track:
- p50 / p95 / p99 latency
- requests per second
- CPU, memory, disk, network
- DB query time
- application logs and timeouts
7. Analyze results
Look for:
- Bottlenecks in app code, DB, or external services
- Increased latency at certain concurrency thresholds
- High error rates
- Resource saturation
- Uneven performance between endpoints
8. Automate and repeat
- Integrate performance tests into CI/CD for smoke-level checks
- Run full load tests on a schedule or before major releases
- Compare results over time to detect regressions
Example with k6
A simple k6 test for a REST endpoint:
import http from 'k6/http';
import { check, sleep } from 'k6';
export const options = {
vus: 10,
duration: '30s',
};
export default function () {
const res = http.get('https://api.example.com/v1/users');
check(res, {
'status is 200': (r) => r.status === 200,
'response time < 500ms': (r) => r.timings.duration < 500,
});
sleep(1);
}
Run it:
k6 run script.js
Best practices
- Test with auth, caching, and database state similar to production
- Avoid testing from a slow or unstable client machine
- Use distributed load generators for high-volume tests
- Monitor the system while the test runs
- Compare results to clear acceptance criteria
If you want, I can also give you:
- a k6 example for POST/PUT requests,
- a JMeter workflow, or
- a step-by-step performance testing plan for your API.