$npx -y skills add ancoleman/ai-design-components --skill performance-engineeringWhen validating system performance under load, identifying bottlenecks through profiling, or optimizing application responsiveness. Covers load testing (k6, Locust), profiling (CPU, memory, I/O), and optimization strategies (caching, query optimization, Core Web Vitals). Use for
| 1 | # Performance Engineering |
| 2 | |
| 3 | ## Purpose |
| 4 | |
| 5 | Performance engineering encompasses load testing, profiling, and optimization to deliver reliable, scalable systems. This skill provides frameworks for choosing the right performance testing approach (load, stress, soak, spike), profiling techniques to identify bottlenecks (CPU, memory, I/O), and optimization strategies for backend APIs, databases, and frontend applications. |
| 6 | |
| 7 | Use this skill to validate system capacity before launch, detect performance regressions in CI/CD pipelines, identify and resolve bottlenecks through profiling, and optimize application responsiveness across the stack. |
| 8 | |
| 9 | ## When to Use This Skill |
| 10 | |
| 11 | **Common Triggers:** |
| 12 | - "Validate API can handle expected traffic" |
| 13 | - "Find maximum capacity and breaking points" |
| 14 | - "Identify why the application is slow" |
| 15 | - "Detect memory leaks or resource exhaustion" |
| 16 | - "Optimize Core Web Vitals for SEO" |
| 17 | - "Set up performance testing in CI/CD" |
| 18 | - "Reduce cloud infrastructure costs" |
| 19 | |
| 20 | **Use Cases:** |
| 21 | - Pre-launch capacity planning and load validation |
| 22 | - Post-refactor performance regression testing |
| 23 | - Investigating slow response times or high latency |
| 24 | - Detecting memory leaks in long-running services |
| 25 | - Optimizing database query performance |
| 26 | - Validating auto-scaling configuration |
| 27 | - Establishing performance SLOs and budgets |
| 28 | |
| 29 | ## Performance Testing Types |
| 30 | |
| 31 | ### Load Testing |
| 32 | Validate system behavior under expected traffic levels. |
| 33 | |
| 34 | **When to use:** Pre-launch capacity planning, regression testing after refactors, validating auto-scaling. |
| 35 | |
| 36 | ### Stress Testing |
| 37 | Find system capacity limits and failure modes. |
| 38 | |
| 39 | **When to use:** Capacity planning, understanding failure behavior, infrastructure sizing decisions. |
| 40 | |
| 41 | ### Soak Testing |
| 42 | Identify memory leaks, resource exhaustion, and degradation over time. |
| 43 | |
| 44 | **When to use:** Detecting memory leaks, validating connection pool cleanup, testing long-running batch jobs. |
| 45 | |
| 46 | ### Spike Testing |
| 47 | Validate system response to sudden traffic spikes. |
| 48 | |
| 49 | **When to use:** Validating auto-scaling, testing event-driven systems (product launches), ensuring rate limiting works. |
| 50 | |
| 51 | ## Quick Decision Framework |
| 52 | |
| 53 | **Which test type to use?** |
| 54 | |
| 55 | ``` |
| 56 | What am I trying to learn? |
| 57 | ├─ Can my system handle expected traffic? → LOAD TEST |
| 58 | ├─ What's the maximum capacity? → STRESS TEST |
| 59 | ├─ Will it stay stable over time? → SOAK TEST |
| 60 | └─ Can it handle traffic spikes? → SPIKE TEST |
| 61 | ``` |
| 62 | |
| 63 | For detailed testing patterns, load scenarios, and interpreting results, see `references/testing-types.md`. |
| 64 | |
| 65 | ## Load Testing Quick Starts |
| 66 | |
| 67 | ### k6 (JavaScript) |
| 68 | |
| 69 | **Installation:** |
| 70 | ```bash |
| 71 | brew install k6 # macOS |
| 72 | sudo apt-get install k6 # Linux |
| 73 | ``` |
| 74 | |
| 75 | **Basic Load Test:** |
| 76 | ```javascript |
| 77 | import http from 'k6/http'; |
| 78 | import { check, sleep } from 'k6'; |
| 79 | |
| 80 | export const options = { |
| 81 | stages: [ |
| 82 | { duration: '30s', target: 20 }, |
| 83 | { duration: '1m', target: 20 }, |
| 84 | { duration: '30s', target: 0 }, |
| 85 | ], |
| 86 | thresholds: { |
| 87 | http_req_duration: ['p(95)<500'], |
| 88 | http_req_failed: ['rate<0.01'], |
| 89 | }, |
| 90 | }; |
| 91 | |
| 92 | export default function () { |
| 93 | const res = http.get('https://api.example.com/products'); |
| 94 | check(res, { |
| 95 | 'status is 200': (r) => r.status === 200, |
| 96 | }); |
| 97 | sleep(1); |
| 98 | } |
| 99 | ``` |
| 100 | |
| 101 | **Run:** `k6 run script.js` |
| 102 | |
| 103 | For stress, soak, and spike testing examples, see `examples/k6/`. |
| 104 | |
| 105 | ### Locust (Python) |
| 106 | |
| 107 | **Installation:** |
| 108 | ```bash |
| 109 | pip install locust |
| 110 | ``` |
| 111 | |
| 112 | **Basic Load Test:** |
| 113 | ```python |
| 114 | from locust import HttpUser, task, between |
| 115 | |
| 116 | class WebsiteUser(HttpUser): |
| 117 | wait_time = between(1, 3) |
| 118 | host = "https://api.example.com" |
| 119 | |
| 120 | @task(3) |
| 121 | def view_products(self): |
| 122 | self.client.get("/products") |
| 123 | |
| 124 | @task(1) |
| 125 | def view_product_detail(self): |
| 126 | self.client.get("/products/123") |
| 127 | ``` |
| 128 | |
| 129 | **Run:** `locust -f locustfile.py --headless -u 100 -r 10 --run-time 10m` |
| 130 | |
| 131 | For REST API testing and data-driven testing, see `examples/locust/`. |
| 132 | |
| 133 | ## Profiling Quick Starts |
| 134 | |
| 135 | ### When to Profile |
| 136 | |
| 137 | | Symptom | Profiling Type | Tool | |
| 138 | |---------|----------------|------| |
| 139 | | High CPU (>70%) | CPU Profiling | py-spy, pprof, DevTools | |
| 140 | | Memory growing | Memory Profiling | memory_profiler, pprof heap | |
| 141 | | Slow response, low CPU | I/O Profiling | Query logs, pprof block | |
| 142 | |
| 143 | ### Python Profiling |
| 144 | |
| 145 | **py-spy (Production-Safe):** |
| 146 | ```bash |
| 147 | pip install py-spy |
| 148 | |
| 149 | # Profile running process |
| 150 | py-spy record -o profile.svg --pid <PID> --duration 30 |
| 151 | |
| 152 | # Top-like view |
| 153 | py-spy top --pid <PID> |
| 154 | ``` |
| 155 | |
| 156 | **Memory Profiling:** |
| 157 | ```python |
| 158 | from memory_profiler import profile |
| 159 | |
| 160 | @profile |
| 161 | def my_function(): |
| 162 | a = [1] * (10 ** 6) |
| 163 | return a |
| 164 | |
| 165 | # Run: python -m memory_profiler script.py |
| 166 | ``` |
| 167 | |
| 168 | ### Go Profiling |
| 169 | |
| 170 | **pprof (Built-in):** |
| 171 | ```go |
| 172 | import ( |
| 173 | "net/http" |