A scalable system stress check program that tracks performance limits under simulated high-concurrency traffic conditions.
- Concurrent Request Simulation: Execute multiple virtual profiles with configurable concurrent users and request rates
- Performance Metrics Tracking: Monitor response times, throughput, and error rates in real-time
- Alerting System: Automatic alerts for performance drops, high error rates, and throughput issues
- Detailed Reports: Generate comprehensive JSON reports with percentile metrics
- Flexible Configuration: Customize test profiles, thresholds, and endpoints
First, install the required dependencies:
npm installThe standalone CLI runner can be used without starting the NestJS application:
# Run with default configuration
npm run stress:test
# Run with custom configuration
npm run stress:test:config ./custom-config.jsonWhen the NestJS application is running, you can use the following endpoints:
These stress-test endpoints are admin-only. They require a valid bearer JWT and an admin role. Unauthenticated requests receive 401 and non-admin JWTs receive 403.
POST /stress-test
Content-Type: application/json
{
"testName": "API Load Test",
"profiles": [
{
"concurrentUsers": 10,
"requestsPerSecond": 50,
"duration": 30,
"endpoint": "/api/health",
"method": "GET"
}
],
"thresholds": {
"maxResponseTime": 1000,
"maxErrorRate": 5,
"minThroughput": 100
},
"enableAlerts": true
}GET /stress-test/active/:testIdGET /stress-test/active{
"testName": "API Load Test",
"baseUrl": "http://localhost:3000",
"profiles": [
{
"concurrentUsers": 10,
"requestsPerSecond": 50,
"duration": 30,
"endpoint": "/api/health",
"method": "GET",
"payload": {}
}
],
"thresholds": {
"maxResponseTime": 1000,
"maxErrorRate": 5,
"minThroughput": 100
},
"enableAlerts": true,
"rampUpTime": 5
}- testName: Name of the stress test
- baseUrl: Target API base URL (default: http://localhost:3000)
- profiles: Array of virtual user profiles
- concurrentUsers: Number of concurrent virtual users (1-10000)
- requestsPerSecond: Target requests per second
- duration: Test duration in seconds
- endpoint: API endpoint to test
- method: HTTP method (GET, POST, PUT, DELETE, PATCH)
- payload: Request body for POST/PUT requests
- thresholds: Performance thresholds for alerts
- maxResponseTime: Maximum acceptable response time in ms
- maxErrorRate: Maximum acceptable error rate percentage
- minThroughput: Minimum acceptable throughput in req/s
- enableAlerts: Enable/disable performance alerts
- rampUpTime: Time to gradually increase load (seconds)
The system tracks the following metrics for each profile:
- Total Requests: Total number of requests sent
- Successful Requests: Number of successful responses (2xx status codes)
- Failed Requests: Number of failed responses
- Throughput: Requests per second
- Average Response Time: Mean response time across all requests
- Percentile Response Times: P50, P95, P99 response times
- Error Rate: Percentage of failed requests
The system generates alerts when performance thresholds are exceeded:
-
PERFORMANCE_DROP (CRITICAL)
- Triggered when average response time exceeds threshold
- Example: Average response time 1500ms exceeds threshold 1000ms
-
ERROR_RATE (CRITICAL)
- Triggered when error rate exceeds threshold
- Example: Error rate 8.5% exceeds threshold 5%
-
THROUGHPUT_DROP (WARNING)
- Triggered when throughput falls below threshold
- Example: Throughput 80 req/s below threshold 100 req/s
After each test run, a detailed JSON report is generated:
stress-test-report-1234567890.jsonThe report includes:
- Test metadata (name, start time, duration)
- Per-profile metrics and alerts
- Overall summary statistics
- Detailed performance data
{
"testName": "Light Load Test",
"profiles": [
{
"concurrentUsers": 5,
"requestsPerSecond": 20,
"duration": 30,
"endpoint": "/api/health",
"method": "GET"
}
],
"thresholds": {
"maxResponseTime": 500,
"maxErrorRate": 1,
"minThroughput": 50
},
"enableAlerts": true
}{
"testName": "Heavy Load Test",
"profiles": [
{
"concurrentUsers": 100,
"requestsPerSecond": 500,
"duration": 120,
"endpoint": "/api/escrow",
"method": "GET"
},
{
"concurrentUsers": 200,
"requestsPerSecond": 1000,
"duration": 180,
"endpoint": "/api/vendor",
"method": "GET"
}
],
"thresholds": {
"maxResponseTime": 2000,
"maxErrorRate": 10,
"minThroughput": 200
},
"enableAlerts": true
}✅ Execution tests trace response behaviors across target concurrent virtual profiles
- Multiple virtual profiles can be configured with different concurrency levels
- Each profile tracks detailed response metrics (times, status codes, errors)
- Percentile metrics (P50, P95, P99) provide insight into response distribution
✅ System alerts flag performance drops or processing errors clearly
- Automatic alerts when response times exceed thresholds
- Error rate alerts when failure rates are too high
- Throughput alerts when system capacity is insufficient
- Clear severity levels (CRITICAL, WARNING) with descriptive messages
- Start Small: Begin with light load tests to establish baseline performance
- Gradual Increase: Use multiple profiles to gradually increase load
- Monitor Resources: Watch CPU, memory, and network during tests
- Set Realistic Thresholds: Base thresholds on your SLA requirements
- Review Reports: Analyze detailed reports to identify bottlenecks
- Test Regularly: Incorporate stress testing into your CI/CD pipeline
- Ensure the target API server is running
- Check the baseUrl configuration matches your server address
- Verify endpoints are accessible and correctly configured
- Check authentication/authorization requirements
- Review server logs for error details
- Monitor server resources during tests
- Check database connection pool settings
- Review rate limiting configurations