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