1
0
Fork 0
loadr/README.md

105 lines
3.1 KiB
Markdown
Raw Permalink Normal View History

2024-12-04 16:40:52 -06:00
# Loadr
2024-12-04 17:45:27 -06:00
A lightweight REST load testing tool with flexible request patterns, token auth, and detailed performance metrics output.
## Stack
- Core: Pure Golang
- Output: Console + CSV/TXT reporting
- Pattern support: Sequential and probabilistic request patterns
- Transport: Standard Go HTTP client
## Requirements
2024-12-04 17:47:02 -06:00
- Golang 1.23.x or higher
2024-12-04 16:40:52 -06:00
## Installation
```bash
go build
```
## Quick Start
```bash
2024-12-04 17:45:27 -06:00
# Simple pattern: 5 POST requests at 20 req/sec
2024-12-04 16:40:52 -06:00
./loadr -rate=20 -max=100 -url=http://api.example.com -pattern=5p
# Mixed pattern: 1 POST followed by 5 GETs, repeating
./loadr -rate=20 -max=100 -url=http://api.example.com -pattern=1p5g
2024-12-04 17:45:27 -06:00
# Probabilistic pattern: 20% POSTs, 80% GETs
./loadr -rate=20 -max=100 -url=http://api.example.com -pattern=20%p80%g
# With auth and request body
2024-12-04 16:40:52 -06:00
./loadr -rate=20 -max=100 -url=http://api.example.com -pattern=2p3g -json=./data.json -token=YourBearerToken
```
## Request Patterns
2024-12-04 17:45:27 -06:00
The `-pattern` flag supports three types of request patterns:
2024-12-04 16:40:52 -06:00
### Simple Patterns
- `5p` : 5 POST requests
- `3g` : 3 GET requests
2024-12-04 17:45:27 -06:00
- Default is `1g` if no pattern specified
2024-12-04 16:40:52 -06:00
### Sequential Patterns
2024-12-04 17:45:27 -06:00
- `1p5g` : 1 POST followed by 5 GETs, repeating
2024-12-04 16:40:52 -06:00
- `2p3g` : 2 POSTs followed by 3 GETs
- `3g2p` : 3 GETs followed by 2 POSTs
2024-12-04 17:45:27 -06:00
### Probabilistic Patterns
- `20%p80%g` : Random selection with 20% POST and 80% GET probability
- Percentages must sum to 100
2024-12-04 16:40:52 -06:00
## Command Line Flags
2024-12-04 17:45:27 -06:00
```bash
-rate Number of requests per second (default: 10)
-max Maximum number of requests to send (default: 50)
-url Target URL (default: "https://example.com")
-pattern Request pattern (e.g., "5p", "1p5g", "20%p80%g")
-json Path to JSON file for request body
-token Bearer token for authorization
-v Print version information
```
2024-12-04 16:40:52 -06:00
2024-12-04 17:45:27 -06:00
## Performance Metrics
2024-12-04 16:40:52 -06:00
2024-12-04 17:45:27 -06:00
Loadr generates two types of reports:
2024-12-04 16:40:52 -06:00
2024-12-04 17:45:27 -06:00
### Summary Report (.reports/summary_[timestamp].txt)
- Total requests sent/received
2024-12-04 16:40:52 -06:00
- Average, maximum, and minimum latency
2024-12-04 17:45:27 -06:00
- Requests/sec (target and actual)
- Latency percentiles (p50, p95, p99)
2024-12-04 16:40:52 -06:00
- Pattern information
2024-12-04 17:45:27 -06:00
### Detailed CSV (.reports/detailed_metrics_[timestamp].csv)
- Per-request timestamps
- Individual request latencies
- Status codes
- Request types
## Technical Details
### Rate Limiting
Loadr uses a time-based approach to approximate the target requests per second:
1. Calculates ideal interval between requests: `interval = 1second / requestsPerSecond`
2. Tracks next scheduled request time
3. Uses sleep to maintain timing between requests
4. Launches requests asynchronously to maintain timing accuracy
### Request Execution
- Uses a global HTTP client for connection reuse
- Requests are executed concurrently using goroutines
- Metrics are updated synchronously using mutex protection
### Metrics Collection
- Real-time tracking of request latencies
- Thread-safe counters for requests and responses
- Calculates percentiles from stored request durations
- Support for detailed CSV export for external analysis
Note: The actual request rate may vary slightly from the target rate due to system load and network conditions. The detailed CSV output can be used to analyze the actual timing distribution.