This document provides comprehensive information about the k6 load and stress testing setup for the Frequency Developer Gateway microservices.
The Gateway project includes extensive k6 load and stress testing capabilities across all microservices. These tests help ensure the reliability, performance, and scalability of the Gateway services under various load conditions.
Before running k6 tests, ensure you have:
- k6 installed: Download from k6.io
- Gateway services running: Use
./start.shto start all services locally - Node.js (version 18 or higher): Required for generating test data and running helper scripts
The Gateway services use different ports when running in Docker containers:
| Service | Internal Port | External Port (Docker) | Purpose |
|---|---|---|---|
| Content Publishing API | 3000 | 3010 | Main API endpoints |
| Content Publishing Worker | 3000 | 3020 | Background processing |
| Content Watcher | 3000 | 3011 | Content monitoring |
| Graph API | 3000 | 3012 | Social graph operations |
| Graph Worker | 3000 | 3022 | Background processing |
| Account API | 3000 | 3013 | Account management |
Note: The k6 tests are configured to target the appropriate ports:
- Standard tests (health checks, v1 endpoints) target port 3000
- v2 batch announcement tests target port 3010 (Docker external port)
- File upload tests target port 3000 (internal container port)
| Test File | Description | Purpose | Port |
|---|---|---|---|
health-check.k6.js |
Basic health check endpoint testing | Verify service availability | 3000 |
new-sign-up.k6.js |
User registration flow testing | Test account creation performance | 3000 |
account-service-load.k6.js |
Comprehensive API load testing | Full service load testing (currently skipped) | 3000 |
signups.gen.js |
Generated test data | Pre generated signup payloads | N/A |
Key Features:
- Test data generation with
npm run generate:signup - Realistic signup payloads to avoid blockchain interaction
- Health check validation before main tests
| Test File | Description | Purpose | Port |
|---|---|---|---|
health-check.k6.js |
Basic health check endpoint testing | Verify service availability | 3000 |
script.k6.js |
Standard API load testing | General service performance | 3000 |
batch-announcement-load.k6.js |
Batch content publishing load testing | Test batch announcement performance | 3010 |
batch-announcement-stress.k6.js |
Advanced stress testing | Comprehensive stress scenarios | 3010 |
script_sm_files.k6.js |
Small file upload testing | Test small file handling | 3000 |
script_md_files.k6.js |
Medium file upload testing | Test medium file handling | 3000 |
script_lg_files.k6.js |
Large file upload testing | Test large file handling | 3000 |
Key Features:
- Multiple load scenarios (light, medium, heavy, burst)
- File size-specific testing
- Realistic batch data generation
- Comprehensive stress testing with multiple phases
Port Configuration:
- Port 3000: Standard API endpoints (v1), health checks, and file upload tests
- Port 3010: v2 batch announcement endpoints (mapped from Docker container port)
| Test File | Description | Purpose | Port |
|---|---|---|---|
health-check.k6.js |
Basic health check endpoint testing | Verify service availability | 3000 |
Key Features:
- Simple health check validation
- Service availability testing
| Test File | Description | Purpose | Port |
|---|---|---|---|
health-check.k6.js |
Basic health check endpoint testing | Verify service availability | 3000 |
script.js |
Standard API load testing | General service performance | 3000 |
Key Features:
- Social graph operation testing
- Relationship management performance testing
The content publishing service includes predefined load testing scenarios:
- VUs: 5
- Duration: 30 seconds
- Purpose: Basic functionality testing
- Thresholds: 99% success rate, less than 2 seconds average response time
- VUs: 20
- Duration: 60 seconds
- Purpose: Normal operation testing
- Thresholds: 98% success rate, less than 5 seconds average response time
- VUs: 200
- Duration: 120 seconds
- Purpose: Stress testing
- Thresholds: 90% success rate, less than 10 seconds average response time
- Stages: Ramp up → Spike → Ramp down
- Purpose: Spike testing
- Thresholds: 90% success rate, less than 15 seconds average response time
The stress testing includes multiple phases:
- Ramp-up Phase: Gradual increase from 1 to 10 VUs over 90 seconds
- Sustained Load: Constant 10 VUs for 2 minutes
- Spike Testing: Arrival rate testing with up to 25 requests per second
- Burst Testing: High-intensity burst of 50 requests per second for 1 minute
cd apps/[service-name]/k6-test
k6 run health-check.k6.jscd apps/content-publishing-api/k6-test
SCENARIO=heavy k6 run batch-announcement-load.k6.jscd apps/content-publishing-api/k6-test
k6 run batch-announcement-stress.k6.jscd apps/content-publishing-api/k6-test
k6 run script_sm_files.k6.js # Small files
k6 run script_md_files.k6.js # Medium files
k6 run script_lg_files.k6.js # Large filescd apps/account-api/k6-test
npm run generate:signupThis generates 100 valid signup payloads in signups.gen.js to avoid blockchain interaction during testing.
The service includes helper functions in helpers.js for generating realistic test data:
createRealisticBatchData(): Creates realistic batch announcement datacreateMultipartBatchData(): Creates multipart form data for file uploads- Various file size scenarios and error conditions
SCENARIO: Select load testing scenario (light, medium, heavy, burst)BASE_URL: Override default service URL (defaults to localhost)
Each test file includes configurable options:
- VUs
- Test duration
- Performance thresholds
- Connection settings
- Custom metrics
- Success Rate: 90% to 99% depending on scenario
- Response Time: Less than 2 to 15 seconds average depending on scenario
- Error Rate: Less than 1% to 20% depending on scenario
- Request Rate: Varies by test type
- Successful requests counter
- Failed requests counter
- Response time trends
- Scenario-specific error rates
The project includes CI/CD tools in tools/ci-k6/ for automated testing:
- Chain setup scripts for testnet testing
- Automated test execution
- Performance reporting
- Start with Health Checks: Always run health checks before load testing
- Use Realistic Data: Generate test data that mimics real usage patterns
- Monitor Resources: Watch system resources during stress testing
- Gradual Scaling: Start with light loads and gradually increase
- Environment Isolation: Run tests against dedicated test environments
- Result Analysis: Review k6 output for performance insights
- Connection Errors: Ensure services are running and accessible
- Port Configuration Errors: Verify you're targeting the correct port for each test type
- Standard API tests: Port 3000
- v2 batch announcement tests: Port 3010
- File upload tests: Port 3000
- EOF Errors: May occur with file uploads; tests include connection settings to handle these
- Timeout Errors: Adjust k6 timeouts for large file uploads
- Memory Issues: Monitor system resources during heavy load testing
Run tests with verbose output:
k6 run --verbose health-check.k6.jsFor more information about k6, visit the official documentation.