Docs
Load Testing Tutorial
Learn how to run load tests with Quadrastack CLI scenarios
Load Testing Tutorial
Learn how to run performance and load tests using Quadrastack CLI.
What You'll Learn
- Create load testing scenarios
- Configure concurrency and rate limits
- Analyze load test results
- Test different load patterns
Prerequisites
- Quadrastack CLI installed
- Basic understanding of scenarios
Step 1: Create Basic API Tests
First, let's create some API requests to test:
# requests.yaml
requests:
get-users:
method: GET
url: https://jsonplaceholder.typicode.com/users
labels: [api, load]
expect:
status: 200
body:
$: type array
$.length: "> 0"
responseTime: "< 2s"
get-posts:
method: GET
url: https://jsonplaceholder.typicode.com/posts
labels: [api, load]
expect:
status: 200
body:
$: type array
$.length: "> 0"
responseTime: "< 2s"
get-user-detail:
method: GET
url: https://jsonplaceholder.typicode.com/users/1
labels: [api, load]
expect:
status: 200
body:
$.id: 1
$.name: !empty
responseTime: "< 2s"
Step 2: Create a Baseline Load Test
Start with a simple baseline test:
# scenarios.yaml
scenarios:
baseline:
description: Baseline performance test with light load
labelSelector: "load"
loadProfile:
concurrency: 5 # 5 concurrent users
duration: "30s" # Run for 30 seconds
Step 3: Run the Baseline Test
quadrastack --scenario baseline
What happens:
- 5 concurrent virtual users
- Each user continuously executes requests with "load" label
- Runs for 30 seconds
- Results show response times, success rate, throughput
Expected output:
Running scenario: baseline
Duration: 30s
Concurrency: 5
Results:
Total requests: 450
Successful: 450 (100%)
Failed: 0 (0%)
Avg response time: 145ms
Min response time: 89ms
Max response time: 312ms
Requests/sec: 15.0
Step 4: Create Progressive Load Tests
Create scenarios with increasing load:
# scenarios.yaml
scenarios:
# Light load - baseline
baseline:
description: Baseline with 5 concurrent users
labelSelector: "load"
loadProfile:
concurrency: 5
duration: "1m"
# Medium load
medium-load:
description: Medium load with 20 concurrent users
labelSelector: "load"
loadProfile:
concurrency: 20
rate: 100 # Limit to 100 req/s
duration: "2m"
# Heavy load
heavy-load:
description: Heavy load with 50 concurrent users
labelSelector: "load"
loadProfile:
concurrency: 50
rate: 200
duration: "5m"
# Stress test
stress-test:
description: Stress test to find breaking point
labelSelector: "load"
loadProfile:
concurrency: 100
rate: 500
duration: "10m"
Advanced Stress Testing
Testing Specific Endpoints
Target specific operations (like writes vs reads) using labels:
scenarios:
read-load:
labelSelector: "load && !write"
loadProfile:
concurrency: 50
duration: "3m"
write-load:
labelSelector: "load-write"
loadProfile:
concurrency: 10
rate: 50
Spike Testing
Test how your API handles sudden traffic jumps:
scenarios:
spike-test:
loadProfile:
concurrency: 200 # Sudden jump
duration: "1m" # Short duration
Soak Testing
Test sustained load to find memory leaks:
scenarios:
soak-test:
loadProfile:
concurrency: 30
rate: 150
duration: "1h" # Long duration
Final Project Structure
load-test-tutorial/
├── requests.yaml
├── scenarios.yaml
└── vars.yaml
Analyzing Results
Results are saved to results/<timestamp>/.
Key Metrics in results.json
successRate: Should be > 99%.p95ResponseTime: The response time that 95% of requests beat.requestsPerSecond: Actual throughput achieved.
Warning Signs
- Success rate drops: Server is overloaded or crashing.
- Latency spikes: Database or resource contention.
- Timeouts: Network or application hangs.
Best Practices
1. Start Small
Always begin with low concurrency and short duration:
scenarios:
initial-test:
loadProfile:
concurrency: 5
duration: "30s"
2. Use Rate Limiting
Prevent overwhelming your API:
scenarios:
controlled-load:
loadProfile:
concurrency: 100
rate: 200 # Max 200 req/s
duration: "5m"
3. Test Non-Production Environments
vars:
staging:
baseUrl: https://staging-api.example.com
# Don't use production for load testing!
# production:
# baseUrl: https://api.example.com
4. Monitor Your Infrastructure
While running load tests, monitor:
- CPU usage
- Memory usage
- Database connections
- Network bandwidth
- Error logs
5. Document Your Findings
Keep a log of load test results:
# Load Test Results
## 2024-01-08: Baseline Test
- Concurrency: 50
- Duration: 5m
- Result: 99.9% success rate, avg 245ms
- Notes: All good at 50 concurrent users
## 2024-01-08: Stress Test
- Concurrency: 200
- Duration: 10m
- Result: 95% success rate, avg 890ms
- Notes: Response times degrade above 150 users
- Action: Optimize database queries
Troubleshooting
High Error Rates
If you see many failures:
- Reduce concurrency
- Add rate limiting
- Check server logs
- Verify network connectivity
Inconsistent Results
If results vary widely:
- Run longer tests (> 5 minutes)
- Ensure stable test environment
- Check for background processes
- Run multiple iterations
Connection Timeouts
# Increase timeout for slow endpoints
httpClients:
patient:
timeout: "60s"
requests:
slow-endpoint:
client: patient
# ...
Next Steps
- Scenarios Guide - Advanced scenario configuration
- HTTP Clients - Configure timeouts and retries