Performance Testing
Table of Contents
Overview
Performance testing measures how systems behave under various load conditions, including response times, throughput, resource utilization, and scalability. It helps identify bottlenecks, validate performance requirements, and ensure systems can handle expected loads.
When to Use
- Validating response time requirements
- Measuring API throughput and latency
- Testing database query performance
- Identifying performance bottlenecks
- Comparing algorithm efficiency
- Benchmarking before/after optimizations
- Validating caching effectiveness
- Testing concurrent user capacity
Quick Start
Minimal working example:
// load-test.js
import http from "k6/http";
import { check, sleep } from "k6";
import { Rate, Trend } from "k6/metrics";
// Custom metrics
const errorRate = new Rate("errors");
const orderDuration = new Trend("order_duration");
// Test configuration
export const options = {
stages: [
{ duration: "2m", target: 10 }, // Ramp up to 10 users
{ duration: "5m", target: 10 }, // Stay at 10 users
{ duration: "2m", target: 50 }, // Ramp up to 50 users
{ duration: "5m", target: 50 }, // Stay at 50 users
{ duration: "2m", target: 0 }, // Ramp down to 0
],
thresholds: {
http_req_duration: ["p(95)<500"], // 95% of requests under 500ms
http_req_failed: ["rate<0.01"], // Error rate under 1%
errors: ["rate<0.1"], // Custom error rate under 10%
},
};
// ... (see reference guides for full implementation)
Reference Guides
Detailed implementations in the references/ directory:
| Guide |
Contents |
| k6 for API Load Testing |
k6 for API Load Testing |
| Apache JMeter |
Apache JMeter |
| pytest-benchmark for Python |
pytest-benchmark for Python |
| JMH for Java Benchmarking |
JMH for Java Benchmarking |
| Database Query Performance |
Database Query Performance |
| Real-Time Monitoring |
Real-Time Monitoring |
Best Practices
✅ DO
- Define clear performance requirements (SLAs)
- Test with realistic data volumes
- Monitor resource utilization
- Test caching effectiveness
- Use percentiles (P95, P99) over averages
- Warm up before measuring
- Run tests in production-like environment
- Identify and fix N+1 query problems
❌ DON'T
- Test only with small datasets
- Ignore memory leaks
- Test in unrealistic environments
- Focus only on average response times
- Skip database indexing analysis
- Test only happy paths
- Ignore network latency
- Compare without statistical significance
1---
2name: performance-testing
3description: >
4 Design and execute performance tests to measure response times, throughput,
5 and resource utilization. Use for performance test, load test, JMeter, k6,
6 benchmark, latency testing, and scalability analysis.
7---
8
9# Performance Testing
10
11## Table of Contents
12
13- [Overview](#overview)
14- [When to Use](#when-to-use)
15- [Quick Start](#quick-start)
16- [Reference Guides](#reference-guides)
17- [Best Practices](#best-practices)
18
19## Overview
20
21Performance testing measures how systems behave under various load conditions, including response times, throughput, resource utilization, and scalability. It helps identify bottlenecks, validate performance requirements, and ensure systems can handle expected loads.
22
23## When to Use
24
25- Validating response time requirements
26- Measuring API throughput and latency
27- Testing database query performance
28- Identifying performance bottlenecks
29- Comparing algorithm efficiency
30- Benchmarking before/after optimizations
31- Validating caching effectiveness
32- Testing concurrent user capacity
33
34## Quick Start
35
36Minimal working example:
37
38```javascript
39// load-test.js
40import http from "k6/http";
41import { check, sleep } from "k6";
42import { Rate, Trend } from "k6/metrics";
43
44// Custom metrics
45const errorRate = new Rate("errors");
46const orderDuration = new Trend("order_duration");
47
48// Test configuration
49export const options = {
50 stages: [
51 { duration: "2m", target: 10 }, // Ramp up to 10 users
52 { duration: "5m", target: 10 }, // Stay at 10 users
53 { duration: "2m", target: 50 }, // Ramp up to 50 users
54 { duration: "5m", target: 50 }, // Stay at 50 users
55 { duration: "2m", target: 0 }, // Ramp down to 0
56 ],
57 thresholds: {
58 http_req_duration: ["p(95)<500"], // 95% of requests under 500ms
59 http_req_failed: ["rate<0.01"], // Error rate under 1%
60 errors: ["rate<0.1"], // Custom error rate under 10%
61 },
62};
63
64// ... (see reference guides for full implementation)
65```
66
67## Reference Guides
68
69Detailed implementations in the `references/` directory:
70
71| Guide | Contents |
72|---|---|
73| [k6 for API Load Testing](references/k6-for-api-load-testing.md) | k6 for API Load Testing |
74| [Apache JMeter](references/apache-jmeter.md) | Apache JMeter |
75| [pytest-benchmark for Python](references/pytest-benchmark-for-python.md) | pytest-benchmark for Python |
76| [JMH for Java Benchmarking](references/jmh-for-java-benchmarking.md) | JMH for Java Benchmarking |
77| [Database Query Performance](references/database-query-performance.md) | Database Query Performance |
78| [Real-Time Monitoring](references/real-time-monitoring.md) | Real-Time Monitoring |
79
80## Best Practices
81
82### ✅ DO
83
84- Define clear performance requirements (SLAs)
85- Test with realistic data volumes
86- Monitor resource utilization
87- Test caching effectiveness
88- Use percentiles (P95, P99) over averages
89- Warm up before measuring
90- Run tests in production-like environment
91- Identify and fix N+1 query problems
92
93### ❌ DON'T
94
95- Test only with small datasets
96- Ignore memory leaks
97- Test in unrealistic environments
98- Focus only on average response times
99- Skip database indexing analysis
100- Test only happy paths
101- Ignore network latency
102- Compare without statistical significance