Comprehensive K6 load testing suite for the Aphrodite streaming platform.
Overview#
This suite includes load tests for:
- Concurrent Viewer Simulation - Tests viewer discovery, stream joining, chat, and tipping
- Tip Storm Simulation - Tests high-volume payment processing and device triggers
- Device Command Flooding - Tests device control APIs under heavy load
- Combined Load Test - Simulates realistic production load with all features
Prerequisites#
- Install K6: https://k6.io/docs/getting-started/installation/
- Ensure Aphrodite services are running
- Configure environment variables if needed
Quick Start#
bash
# Run concurrent viewer simulation
k6 run testing/performance/k6/aphrodite/viewer-simulation.js
# Run tip storm simulation
k6 run testing/performance/k6/aphrodite/tip-storm.js
# Run device command flooding
k6 run testing/performance/k6/aphrodite/device-flooding.js
# Run combined load test (recommended for production validation)
k6 run testing/performance/k6/aphrodite/combined-load-test.js
Configuration#
Environment Variables#
| Variable | Default | Description |
|---|---|---|
APHRODITE_API_URL |
http://localhost:3100 |
Main API URL |
APHRODITE_STREAMING_URL |
http://localhost:3101 |
Streaming service URL |
APHRODITE_BROADCASTER_URL |
http://localhost:3102 |
Broadcaster service URL |
APHRODITE_VIEWER_URL |
http://localhost:3103 |
Viewer service URL |
APHRODITE_CHAT_URL |
http://localhost:3104 |
Chat service URL |
APHRODITE_PAYMENT_URL |
http://localhost:3105 |
Payment service URL |
APHRODITE_DEVICES_URL |
http://localhost:3106 |
Devices service URL |
JWT_SECRET |
aphrodite-load-test-secret |
JWT signing secret |
Example with Custom URLs#
bash
k6 run \
-e APHRODITE_STREAMING_URL=http://staging.aphrodite.io:3101 \
-e APHRODITE_PAYMENT_URL=http://staging.aphrodite.io:3105 \
testing/performance/k6/aphrodite/combined-load-test.js
Test Files#
config.js#
Shared configuration and helper functions:
- Service URLs
- Custom metrics
- Test user data
- JWT token generation
- API helper functions
- Health check utilities
- Report generation
viewer-simulation.js#
Simulates concurrent viewers:
- Stream discovery
- Stream joining/leaving
- Chat participation
- Tipping behavior
- Viewer spike scenarios
Scenarios:
ramp_viewers: Gradual ramp to 1000 concurrent viewersviewer_spike: Sudden influx of 500 viewers
Thresholds:
- HTTP P95 < 1000ms
- Stream discovery P95 < 500ms
- Stream join P95 < 1000ms
- Chat message P95 < 300ms
tip-storm.js#
Simulates high-volume tipping:
- Sustained tip rate (100/sec)
- Burst tip scenarios (up to 1000/sec)
- Device trigger integration
- Leaderboard checks
- Earnings tracking
Scenarios:
sustained_storm: 100 tips/second for 5 minutesburst_storm: Bursts up to 1000 tips/secondtop_tipper: 200 tips/second to single broadcaster
Thresholds:
- Tip processing P95 < 1500ms
- Device trigger P95 < 500ms
- At least 1000 successful tips
device-flooding.js#
Simulates device command flooding:
- Vibrate commands
- Stop commands
- Pattern execution
- Batch device control
- Tip trigger simulation
Scenarios:
sustained_commands: 50 commands/secondcommand_burst: Bursts up to 500 commands/secondbatch_operations: 30 batch operations/secondstress_test: Escalating to 1000 commands/second
Thresholds:
- Vibrate P95 < 300ms
- Stop P95 < 200ms
- Pattern P95 < 400ms
- Batch P95 < 800ms
combined-load-test.js#
Realistic production simulation:
- All services running simultaneously
- Viewer, tip, and device traffic
- Peak hour simulation
Scenarios:
viewer_traffic: Up to 300 concurrent viewerstip_traffic: Up to 150 tips/seconddevice_traffic: Up to 100 commands/secondpeak_hour: Combined load with 500 VUs
Output#
Each test generates:
- JSON summary file (e.g.,
aphrodite-viewer-simulation-summary.json) - Console report with key metrics
Metrics#
Custom Metrics#
| Metric | Type | Description |
|---|---|---|
api_latency |
Trend | General API call latency |
streaming_latency |
Trend | Streaming service latency |
payment_latency |
Trend | Payment service latency |
device_latency |
Trend | Device service latency |
chat_latency |
Trend | Chat service latency |
tips_processed |
Counter | Successful tips |
viewers_joined |
Counter | Viewers who joined streams |
device_commands |
Counter | Device commands sent |
errors |
Rate | Custom error rate |
Best Practices#
- Warm up services before running full load tests
- Run in isolation to avoid interference from other traffic
- Monitor resources (CPU, memory, DB connections) during tests
- Compare results between runs to track regressions
- Start small and gradually increase load to find limits
Troubleshooting#
Services unhealthy#
Ensure all Aphrodite services are running:
bash
docker compose -f docker/docker-compose.dev.yml up -d
Rate limiting#
If seeing many 429 responses, the services are rate limiting correctly. Adjust thresholds or test configuration accordingly.
Token errors#
Ensure JWT_SECRET matches the services' configuration.
CI/CD Integration#
Add to your CI pipeline:
yaml
- name: Run Load Tests
run: |
k6 run --out json=results.json \
testing/performance/k6/aphrodite/combined-load-test.js
Contributing#
When adding new tests:
- Use
config.jsfor shared utilities - Follow the existing naming conventions
- Add appropriate thresholds
- Include custom metrics for tracking
- Generate detailed summary reports