A comprehensive traffic generation tool using wrk
that creates realistic load testing scenarios with multiple hosts and APIs using company data as payload.
- Configurable Hosts & APIs: Generate traffic to configurable number of unique hosts and API endpoints
- Realistic Payloads: Uses company schema data to generate realistic JSON payloads
- Multiple HTTP Methods: Supports both POST and PUT requests
- Random Data Generation: Creates varied, realistic company information
- Comprehensive Logging: Detailed performance metrics and error reporting
- Flexible Configuration: Easy to customize test parameters
macOS:
brew install wrk
Ubuntu/Debian:
sudo apt-get install wrk
CentOS/RHEL:
sudo yum install wrk
Run with default settings (1000 unique hosts, 1000 unique APIs):
./run-traffic-test.sh
./run-traffic-test.sh [unique_hosts] [unique_apis] [duration] [threads] [connections] [target_url]
Parameters:
unique_hosts
: Number of unique hosts to target (default: 1000)unique_apis
: Number of unique API endpoints (default: 1000)duration
: Test duration in seconds (default: 30)threads
: Number of threads (default: 4)connections
: Number of connections (default: 100)target_url
: Base URL for requests (default: http://localhost:8085)
Basic test with 500 hosts and 500 APIs:
./run-traffic-test.sh 500 500
High-load test with custom parameters:
./run-traffic-test.sh 2000 2000 60 8 200 http://api.example.com
Short test for development:
./run-traffic-test.sh 100 100 10 2 50 http://localhost:8085
Source the test configurations and run predefined tests:
source test-configs.sh
# Run a smoke test (quick 10-second test)
smoke_test
# Run a light load test
light_test
# Run a medium load test
medium_test
# Run a heavy load test
heavy_test
# Run an extreme load test
extreme_test
You can also run wrk directly with the Lua script:
wrk -t4 -c100 -d30s -s traffic-generator.lua --latency http://localhost:8085 1000 1000
The script generates hosts in the format:
http://api-{1..N}.example.com:{8000..9000}
https://api-{1..N}.example.com:{8000..9000}
Generated API patterns include:
/api/v1/companies
/api/v2/companies
/companies
/business/companies
/data/companies
/rest/companies
/graphql/companies
- And more with random suffixes
Each request contains a randomly generated company object based on the company-schema.json
:
{
"companyId": "COMP-abc12345",
"companyName": "TechCorp xyz9",
"headquarters": {
"address": {
"street": "1234 Main St",
"city": "San Francisco",
"state": "CA",
"zipCode": "94105",
"country": "USA"
},
"contact": {
"phone": "+1-555-123-4567",
"email": "[email protected]",
"fax": "+1-555-987-6543"
}
},
"financials": {
"revenue": 50000000,
"employees": 250,
"valuation": 100000000,
"departments": {
"engineering": {
"headcount": 100,
"budget": 5000000,
"location": "San Francisco"
},
"sales": {
"headcount": 50,
"budget": 2000000,
"region": "CA"
}
}
},
"metadata": {
"founded": "2010",
"industry": "Technology",
"description": "A leading Technology company focused on innovation and growth.",
"legal": {
"taxId": "TAX-12345678",
"registration": "REG-87654321",
"status": "ACTIVE"
}
}
}
Each request includes:
Content-Type: application/json
Accept: application/json
User-Agent: wrk-traffic-generator/1.0
X-Request-ID: {random-16-char-string}
X-Client-ID: client-{random-8-char-string}
- Optional:
X-Correlation-ID
,Authorization
(randomly added)
The script displays real-time metrics including:
- Requests per second
- Latency statistics
- Error counts
- 95th percentile latency
All test results are saved to logs/traffic_test_YYYYMMDD_HHMMSS.log
- Memory Usage: Large numbers of unique hosts/APIs may increase memory usage
- Network Load: High connection counts may saturate network interfaces
- Target Capacity: Ensure your target system can handle the generated load
- Monitoring: Monitor system resources during testing
Edit the generate_host()
function in traffic-generator.lua
to change host patterns.
Modify the api_patterns
array in the generate_api()
function.
Update the sample data arrays (company names, industries, cities, etc.) in the Lua script.
Modify the method selection logic in the request()
function.
- wrk not found: Install wrk using the instructions above
- Permission denied: Make sure the shell script is executable (
chmod +x run-traffic-test.sh
) - High error rates: Check if the target URL is accessible and can handle the load
- Memory issues: Reduce the number of unique hosts/APIs or connection count
For debugging, you can modify the Lua script to log more information by uncommenting print statements or adding custom logging.
This project is open source and available under the MIT License.