Comprehensive load testing system for performance analysis and optimization.
Create and manage load testing scenarios with configurable parameters.
import { LoadTestScenario } from './loadTesting/index.js';
const scenario = new LoadTestScenario('payment-flow', 'Payment processing test');
scenario.addRequest('GET', '/api/health');
scenario.addRequest('POST', '/api/stellar/account/create', {}, 1);
scenario.addRequest('POST', '/api/stellar/payment/send', { amount: '100' }, 5);
scenario.setDuration(120).setRampUp(20).setConcurrency(50);
await scenario.save();API Endpoint:
POST /api/load-testing/scenarios/create- Create scenario
Establish and track performance baselines for regression detection.
import { PerformanceBaseline, LoadTestRunner } from './loadTesting/index.js';
const runner = new LoadTestRunner();
const results = await runner.runScenario(scenario);
const baseline = new PerformanceBaseline('payment-flow');
baseline.calculateFromResults(results);
await baseline.save();API Endpoints:
POST /api/load-testing/baseline/establish- Establish baselineGET /api/load-testing/baseline/latest/:scenarioName- Get latest baseline
Detect performance regressions automatically.
import { regressionTester } from './loadTesting/index.js';
const regressions = regressionTester.detectRegression(currentResults, baseline);
const report = regressionTester.generateReport(regressions);
// { status: 'PASS' | 'WARN' | 'FAIL', summary: {...}, regressions: [...] }API Endpoint:
POST /api/load-testing/regression/check- Check for regressions
Calculate maximum capacity and scaling needs.
import { capacityPlanner } from './loadTesting/index.js';
// Calculate current capacity
const capacity = capacityPlanner.calculateCapacity(results, targetErrorRate);
// { currentThroughput, maxSafeThroughput, maxCapacity, headroom, recommendations }
// Project scaling needs
const projection = capacityPlanner.estimateScalingNeeds(throughput, growthRate, months);
// { currentThroughput, projectedThroughput, scalingFactor, recommendations }API Endpoints:
POST /api/load-testing/capacity/calculate- Calculate capacityPOST /api/load-testing/capacity/project- Project scaling needs
Identify and analyze performance bottlenecks.
import { bottleneckAnalyzer } from './loadTesting/index.js';
const bottlenecks = bottleneckAnalyzer.analyze(results);
const recommendations = bottleneckAnalyzer.getRecommendations(bottlenecks);API Endpoint:
POST /api/load-testing/bottlenecks/analyze- Analyze bottlenecks
Real-time performance alerting with configurable thresholds.
import { performanceAlerting } from './loadTesting/index.js';
performanceAlerting.setThreshold('avgResponseTime', 1000);
performanceAlerting.setThreshold('errorRate', 5);
const alerts = performanceAlerting.checkMetrics(results);
await performanceAlerting.saveAlerts();API Endpoints:
POST /api/load-testing/alerts/check- Check metrics and generate alertsGET /api/load-testing/alerts- Get all alertsGET /api/load-testing/alerts/critical- Get critical alerts
Get actionable optimization recommendations.
import { optimizationRecommender } from './loadTesting/index.js';
const recommendations = optimizationRecommender.generateRecommendations(results, bottlenecks);
const prioritized = optimizationRecommender.prioritizeRecommendations(recommendations);API Endpoint:
POST /api/load-testing/recommendations- Get optimization recommendations
Run load tests and collect results.
import { LoadTestRunner } from './loadTesting/index.js';
const runner = new LoadTestRunner();
const results = await runner.runScenario(scenario, 'http://localhost:3001');
const saved = await runner.saveResults('payment-flow');API Endpoints:
POST /api/load-testing/run- Run load testGET /api/load-testing/results/:scenarioName- Get test results
- Response Time: Min, max, average, p50, p95, p99
- Throughput: Requests per second
- Error Rate: Percentage of failed requests
- Success Count: Total successful requests
- Error Count: Total failed requests
- Duration: Total test duration
data/load-tests/
├── scenarios/ # Test scenarios (JSON)
├── baselines/ # Performance baselines (JSON)
├── results/ # Test results (JSON)
└── alerts/ # Performance alerts (JSON)
- Average Response Time: 1000ms
- P95 Response Time: 2000ms
- Error Rate: 5%
- Throughput: 10 req/s
- Average Response Time: 10% increase
- P95 Response Time: 15% increase
- Error Rate: 5% increase
- Throughput: 10% decrease
Severity is calculated based on:
- Average response time (0-3 points)
- P95 response time (0-3 points)
- Error rate (0-3 points)
Calculates:
- Current throughput
- Maximum safe throughput (based on error rate)
- Maximum capacity (based on response time)
- Headroom percentage
- Scaling recommendations
Estimates:
- Projected throughput based on growth rate
- Scaling factor needed
- Recommendations for horizontal/vertical scaling
- Caching and optimization strategies
curl -X POST http://localhost:3001/api/load-testing/scenarios/create \
-H "Content-Type: application/json" \
-d '{
"name": "payment-flow",
"description": "Payment processing test",
"requests": [
{"method": "GET", "path": "/api/health", "weight": 1},
{"method": "POST", "path": "/api/stellar/payment/send", "weight": 5}
],
"duration": 120,
"rampUp": 20,
"concurrency": 50
}'curl -X POST http://localhost:3001/api/load-testing/run \
-H "Content-Type: application/json" \
-d '{"scenarioName": "payment-flow"}'curl -X POST http://localhost:3001/api/load-testing/regression/check \
-H "Content-Type: application/json" \
-d '{"scenarioName": "payment-flow"}'curl -X POST http://localhost:3001/api/load-testing/recommendations \
-H "Content-Type: application/json" \
-d '{"scenarioName": "payment-flow"}'curl -X POST http://localhost:3001/api/load-testing/capacity/calculate \
-H "Content-Type: application/json" \
-d '{"scenarioName": "payment-flow", "targetErrorRate": 1}'curl -X POST http://localhost:3001/api/load-testing/capacity/project \
-H "Content-Type: application/json" \
-d '{"scenarioName": "payment-flow", "growthRate": 0.2, "months": 12}'Add to your CI/CD pipeline:
# .github/workflows/performance.yml
name: Performance Testing
on: [push, pull_request]
jobs:
load-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Run load tests
run: |
npm run load-test
- name: Check regressions
run: |
npm run check-regression
- name: Generate report
run: |
npm run performance-reportRun load testing tests:
npm test -- loadTesting.test.js- Establish Baselines: Create baselines before making changes
- Regular Testing: Run load tests regularly (daily/weekly)
- Monitor Trends: Track performance over time
- Act on Alerts: Investigate and fix critical alerts
- Document Changes: Record optimization efforts
- Capacity Planning: Plan for growth proactively
- Realistic Scenarios: Use realistic user behavior patterns
- Gradual Ramp-up: Use ramp-up to simulate real traffic
- Caching: Implement Redis/Memcached for frequently accessed data
- Database: Add indexes, optimize queries, use connection pooling
- Async: Use async/await patterns for I/O operations
- Batching: Batch requests where possible
- Circuit Breakers: Implement circuit breakers for external services
- Monitoring: Use APM tools for detailed insights
- Scaling: Plan horizontal scaling for high-traffic scenarios
- Testing: Conduct regular load tests and regression testing
- Distributed load testing
- Real-time dashboards
- Advanced analytics
- Machine learning-based anomaly detection
- Integration with monitoring tools
- Automated scaling recommendations
- Cost optimization analysis