Initial commit

This commit is contained in:
Zhongwei Li
2025-11-30 08:23:21 +08:00
commit 2e4c7302a4
11 changed files with 852 additions and 0 deletions

View File

@@ -0,0 +1,56 @@
---
name: performance-testing
description: |
This skill enables Claude to design, execute, and analyze performance tests using the performance-test-suite plugin. It is activated when the user requests load testing, stress testing, spike testing, or endurance testing, and when discussing performance metrics such as response time, throughput, and error rates. It identifies performance bottlenecks related to CPU, memory, database, or network issues. The plugin provides comprehensive reporting, including percentiles, graphs, and recommendations.
allowed-tools: Read, Write, Edit, Grep, Glob, Bash
version: 1.0.0
---
## Overview
This skill automates performance testing workflows, allowing Claude to create and run various tests to assess system performance under different conditions. It facilitates bottleneck identification and provides actionable recommendations for optimization.
## How It Works
1. **Test Design**: Claude analyzes the user's request to determine the appropriate test type (load, stress, spike, or endurance) and configures test parameters such as target users, duration, and ramp-up time.
2. **Test Execution**: The performance-test-suite plugin executes the designed test, collecting performance metrics like response times, throughput, and error rates.
3. **Metrics Analysis**: Claude analyzes the collected metrics to identify performance bottlenecks and potential issues.
4. **Report Generation**: Claude generates a comprehensive report summarizing the test results, highlighting key performance indicators, and providing recommendations for improvement.
## When to Use This Skill
This skill activates when you need to:
- Create a load test for an API.
- Design a stress test to determine the breaking point of a system.
- Simulate a spike test to evaluate system behavior during sudden traffic surges.
- Develop an endurance test to detect memory leaks or stability issues.
## Examples
### Example 1: Load Testing an API
User request: "Create a load test for the /users API, ramping up to 200 concurrent users over 10 minutes."
The skill will:
1. Design a load test configuration with a ramp-up stage to 200 users over 10 minutes.
2. Execute the load test using the performance-test-suite plugin.
3. Generate a report showing response times, throughput, and error rates for the /users API.
### Example 2: Stress Testing a Checkout Process
User request: "Design a stress test to find the breaking point of the checkout process."
The skill will:
1. Design a stress test configuration with gradually increasing load on the checkout process.
2. Execute the stress test, monitoring response times and error rates.
3. Identify the point at which the checkout process fails and generate a report detailing the system's breaking point.
## Best Practices
- **Realistic Scenarios**: Design tests that accurately reflect real-world usage patterns.
- **Comprehensive Metrics**: Monitor a wide range of performance metrics to gain a holistic view of system performance.
- **Iterative Testing**: Run multiple tests with different configurations to fine-tune performance and identify optimal settings.
## Integration
This skill integrates with other monitoring and alerting plugins to provide real-time feedback on system performance during testing. It can also be used in conjunction with deployment plugins to automatically validate performance after code changes.

View File

@@ -0,0 +1,7 @@
# Assets
Bundled resources for performance-test-suite skill
- [ ] test_template.js: Template file for creating k6 performance tests.
- [ ] report_template.html: HTML template for generating performance test reports.
- [ ] example_test_configurations.json: Example configurations for different types of performance tests.

View File

@@ -0,0 +1,121 @@
[
{
"_comment": "Example configuration for a basic load test with gradual ramp-up",
"test_name": "Basic Load Test - Ramp Up",
"test_type": "load",
"description": "Simulates a gradual increase in users to test system responsiveness under increasing load.",
"target_url": "https://example.com/api/users",
"http_method": "GET",
"num_users": 100,
"ramp_up_time": 60,
"duration": 300,
"request_body": null,
"headers": {
"Content-Type": "application/json",
"Accept": "application/json"
},
"assertions": [
{
"type": "status_code",
"value": 200
},
{
"type": "response_time",
"max_ms": 500
}
],
"metrics": [
"response_time",
"requests_per_second",
"error_rate"
]
},
{
"_comment": "Example configuration for a stress test to find the breaking point",
"test_name": "Stress Test - Breaking Point",
"test_type": "stress",
"description": "Gradually increases load until the system reaches its breaking point.",
"target_url": "https://example.com/api/products",
"http_method": "POST",
"num_users": 500,
"ramp_up_time": 120,
"duration": 600,
"request_body": {
"product_name": "Test Product",
"price": 99.99
},
"headers": {
"Content-Type": "application/json"
},
"assertions": [
{
"type": "status_code",
"value": 201
}
],
"metrics": [
"cpu_usage",
"memory_usage",
"database_connections",
"error_rate"
]
},
{
"_comment": "Example configuration for a spike test simulating a flash sale",
"test_name": "Spike Test - Flash Sale",
"test_type": "spike",
"description": "Simulates a sudden surge in traffic to test system resilience.",
"target_url": "https://example.com/api/orders",
"http_method": "POST",
"num_users": 2000,
"ramp_up_time": 10,
"duration": 60,
"request_body": {
"user_id": 123,
"product_id": 456,
"quantity": 1
},
"headers": {
"Content-Type": "application/json"
},
"assertions": [
{
"type": "status_code",
"value": 201
}
],
"metrics": [
"response_time",
"requests_per_second",
"error_rate",
"database_queue_length"
]
},
{
"_comment": "Example configuration for an endurance test to check for memory leaks",
"test_name": "Endurance Test - Memory Leak Check",
"test_type": "endurance",
"description": "Runs a sustained load for an extended period to detect memory leaks and performance degradation.",
"target_url": "https://example.com/api/data",
"http_method": "GET",
"num_users": 50,
"ramp_up_time": 30,
"duration": 3600,
"request_body": null,
"headers": {
"Authorization": "Bearer <your_api_key>"
},
"assertions": [
{
"type": "status_code",
"value": 200
}
],
"metrics": [
"memory_usage",
"cpu_usage",
"response_time",
"garbage_collection_count"
]
}
]

View File

@@ -0,0 +1,203 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Performance Test Report</title>
<style>
/* Inline CSS for styling */
body {
font-family: sans-serif;
margin: 0;
padding: 0;
background-color: #f4f4f4;
color: #333;
}
.container {
width: 90%;
max-width: 1200px;
margin: 20px auto;
background-color: #fff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
h1, h2, h3 {
color: #0056b3;
margin-bottom: 10px;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
th, td {
padding: 10px;
text-align: left;
border-bottom: 1px solid #ddd;
}
th {
background-color: #f2f2f2;
}
.summary {
margin-top: 20px;
padding: 15px;
background-color: #e9ecef;
border-radius: 5px;
}
.summary p {
margin: 5px 0;
}
.charts {
display: flex;
flex-wrap: wrap;
justify-content: space-around;
margin-top: 20px;
}
.chart {
width: 45%;
min-width: 300px;
margin-bottom: 20px;
border: 1px solid #ddd;
padding: 10px;
border-radius: 5px;
box-sizing: border-box; /* Important for padding */
}
.chart img {
max-width: 100%;
height: auto;
}
@media (max-width: 768px) {
.container {
width: 95%;
}
.chart {
width: 100%;
}
}
.bottlenecks {
margin-top: 20px;
padding: 15px;
background-color: #ffebee;
border-radius: 5px;
border: 1px solid #ef9a9a;
}
.bottlenecks h3 {
color: #d32f2f;
}
.recommendations {
margin-top: 20px;
padding: 15px;
background-color: #e8f5e9;
border-radius: 5px;
border: 1px solid #a5d6a7;
}
.recommendations h3 {
color: #388e3c;
}
</style>
</head>
<body>
<!-- Main Container -->
<div class="container">
<!-- Report Header -->
<h1>Performance Test Report</h1>
<p>Test Run: {{test_run_id}}</p>
<p>Date: {{report_date}}</p>
<!-- Test Summary -->
<div class="summary">
<h2>Test Summary</h2>
<p><strong>Test Type:</strong> {{test_type}}</p>
<p><strong>Target URL:</strong> {{target_url}}</p>
<p><strong>Number of Users:</strong> {{number_of_users}}</p>
<p><strong>Duration:</strong> {{duration}}</p>
<p><strong>Status:</strong> {{test_status}}</p>
</div>
<!-- Key Metrics Table -->
<h2>Key Metrics</h2>
<table>
<thead>
<tr>
<th>Metric</th>
<th>Value</th>
</tr>
</thead>
<tbody>
<tr>
<td>Average Response Time</td>
<td>{{average_response_time}} ms</td>
</tr>
<tr>
<td>Throughput</td>
<td>{{throughput}} requests/second</td>
</tr>
<tr>
<td>Error Rate</td>
<td>{{error_rate}} %</td>
</tr>
<tr>
<td>95th Percentile Response Time</td>
<td>{{percentile_95_response_time}} ms</td>
</tr>
</tbody>
</table>
<!-- Charts -->
<div class="charts">
<div class="chart">
<h3>Response Time Over Time</h3>
<img src="{{response_time_chart_url}}" alt="Response Time Chart">
</div>
<div class="chart">
<h3>Throughput Over Time</h3>
<img src="{{throughput_chart_url}}" alt="Throughput Chart">
</div>
<!-- Add more charts as needed -->
</div>
<!-- Bottleneck Identification -->
<div class="bottlenecks">
<h3>Bottleneck Identification</h3>
<p>{{bottlenecks_summary}}</p>
<ul>
{{#bottlenecks}}
<li>{{.}}</li>
{{/bottlenecks}}
</ul>
</div>
<!-- Recommendations -->
<div class="recommendations">
<h3>Recommendations</h3>
<p>{{recommendations_summary}}</p>
<ul>
{{#recommendations}}
<li>{{.}}</li>
{{/recommendations}}
</ul>
</div>
</div>
</body>
</html>

View File

@@ -0,0 +1,65 @@
// test_template.js - Template for K6 performance tests
// Import necessary modules from K6
import http from 'k6/http';
import { check, sleep } from 'k6';
// Configuration options
export const options = {
// Stages define the load pattern
stages: [
// Example: Ramp-up to 10 virtual users (VUs) over 10 seconds
{ duration: '10s', target: 10 },
// Example: Maintain 10 VUs for 30 seconds
{ duration: '30s', target: 10 },
// Example: Ramp-down to 0 VUs over 10 seconds
{ duration: '10s', target: 0 },
],
// Thresholds define pass/fail criteria
thresholds: {
// Example: 95th percentile response time should be below 200ms
http_req_duration: ['p95<200'],
// Example: 99% of requests should be successful
http_req_failed: ['rate<0.01'], // <1% failure rate
},
};
// Define the virtual user (VU) function
export default function () {
// Replace with your target URL
const url = 'YOUR_TARGET_URL_HERE';
// Replace with your request parameters (optional)
const params = {
headers: {
'Content-Type': 'application/json',
},
};
// Replace with your request body (optional)
const payload = JSON.stringify({
key1: 'value1',
key2: 'value2',
});
// Make an HTTP request
const res = http.get(url, params); // or use http.post, http.put, http.delete, etc.
// Check the response status code
check(res, {
'status is 200': (r) => r.status === 200,
});
// Add more checks as needed
// Example: check(res, { 'response time < 500ms': (r) => r.timings.duration < 500 });
// Introduce a delay between requests (optional)
sleep(1); // Sleep for 1 second
// Log response data for debugging (optional - REMOVE IN PRODUCTION!)
// console.log(res.body);
}

View File

@@ -0,0 +1,7 @@
# References
Bundled resources for performance-test-suite skill
- [ ] k6_api_reference.md: Documentation for the k6 API used in the performance tests.
- [ ] performance_metrics_guide.md: Guide explaining various performance metrics and their significance.
- [ ] test_design_best_practices.md: Best practices for designing effective performance tests.

View File

@@ -0,0 +1,7 @@
# Scripts
Bundled resources for performance-test-suite skill
- [ ] init_test.py: Script to initialize a performance test based on user input.
- [ ] run_test.sh: Script to execute the performance test using k6 or other tools.
- [ ] analyze_results.py: Script to analyze the test results and generate a report.