How to Build a Simple Performance Testing Plan for an API
An API can work perfectly when you're testing it with a few requests. The real problems often appear when multiple users start sending requests at the same time.
Response times increase, errors begin to appear, or the server struggles to keep up. Without performance testing, it's difficult to know how much traffic your API can handle before these problems occur.
You don't need a complicated setup to get started. A small, well-planned test can already tell you a lot about your API's behavior under load.
In this tutorial, we'll build a simple performance testing plan using Apache JMeter and walk through the decisions you should make before running a test.
- Choose the API Endpoint
Start with one endpoint rather than testing your entire application at once.
For this example, let's say you're working with a product API:
GET /api/products
The endpoint returns a list of products. Your goal is to understand how it performs when several users request the data simultaneously.
Before testing, confirm a few things:
- The endpoint and HTTP method you're testing.
- Whether authentication is required.
- What a successful response should look like.
- Whether the endpoint depends on a database or another service.
- Which environment you're allowed to test.
Use a staging environment or another explicitly authorized target. Avoid sending heavy test traffic to a third-party API or a production service without permission.
- Decide What Traffic to Simulate
A useful test should reflect how people actually use your API.
For a starting point, consider three scenarios.
Normal load: Simulate 10 concurrent users to establish a baseline.
Expected peak load: Increase the traffic to 50 concurrent users to see how the API behaves during a busier period.
Higher load: Try 100 concurrent users to look for performance degradation, provided the test environment can safely handle it.
These numbers are examples, not universal benchmarks. Choose values that make sense for your application and test environment.
Also, don't jump straight to the highest load. Increase traffic gradually so you can identify when response times start rising or errors become more frequent.
- Choose the Metrics That Matter
A test that reports only the number of successful requests doesn't tell the whole story.
Track these metrics:
| Metric | Why it matters |
|---|---|
| Response time | Shows how long requests take to complete |
| Throughput | Measures how many requests the API handles over time |
| Error rate | Reveals failed requests and server errors |
| p95 latency | Shows the response time at or below which 95% of requests completed |
| CPU and memory | Helps identify resource constraints on the server |
For example, an API might handle 200 requests per second but still feel slow because its p95 response time has climbed to three seconds.
Set your acceptance criteria before running the test. You might decide that the API should keep p95 latency below 500 milliseconds with an error rate under 1% at the expected peak load. Those are sample targets; your actual limits should reflect the needs of your application.
- Create a Simple Test in JMeter
Install Apache JMeter and create a new test plan.
Add a Thread Group to represent virtual users. For an initial test, configure 10 threads, a ramp-up period of 20 seconds, and a small number of iterations.
Next, add an HTTP Request sampler with these settings:
- Protocol:
https - Server name: Your authorized test server
- Method:
GET - Path:
/api/products
Add an HTTP Header Manager if your endpoint requires headers, such as an authorization token or an Accept: application/json header.
For authentication, use a test account and keep secrets out of shared test files.
Add a listener such as Summary Report to review the results during a small trial. For larger tests, prefer JMeter's non-GUI mode and save the results to a file, rather than relying on heavy graphical listeners.
For example, after saving the test plan as api-test.jmx, run:
jmeter -n -t api-test.jmx -l results.jtl
This runs the test without the graphical interface and writes the results to results.jtl.
Start with a small number of users. Confirm that the endpoint returns the expected status code and that the test is measuring the intended requests before increasing the load.
- Run the Test and Review the Results
Once the basic test works, increase the load gradually and compare the results across runs.
Look for patterns rather than focusing on a single number.
If response times increase as users are added, check whether CPU usage is rising, database queries are slowing down, or connection pools are reaching their limits.
If the error rate increases, inspect the response codes and application logs. A rise in HTTP 429 responses, for example, may indicate rate limiting rather than a server failure.
If throughput stops increasing even as you add more users, the API may have reached a bottleneck. However, the test generator itself could also be running out of resources, so monitor the machine generating traffic as well.
Repeat tests under similar conditions where possible. Background jobs, cache state, network conditions, and other workloads can affect the results.
- Turn the Results Into an Action Plan
The purpose of performance testing isn't just to collect numbers. It's to identify what needs attention.
Record the test configuration, number of users, duration, response-time percentiles, throughput, error rate, and relevant infrastructure metrics.
If the API misses its targets, investigate the likely bottleneck and make one change at a time. Then run the same test again to see whether the change actually improved performance.
This also gives you a useful baseline for future releases. You can compare results after code changes and catch regressions before they reach users.
Top comments (0)