loadgen
A standalone, asyncio-based HTTP load-generation engine. It sends a configured number of requests per second against a target API for a configured duration, then prints a latency and success report.
Overview
loadgen answers a narrow question: what happens to my API when I send N requests per second for M seconds? It is a single-process command-line engine, not a distributed load-testing platform. Configuration is a YAML file; results are printed to stdout as a text report.
The engine separates three concerns:
- Scheduling — a fixed-rate clock decides when requests are launched.
- Execution — a semaphore caps how many requests are in flight at once.
- Observation — every request becomes an immutable sample; metrics are aggregated once, after the run.
Features
Implemented:
- YAML configuration validated with Pydantic before any traffic is generated
- Fixed-rate request pacing on a monotonic clock
- Configurable concurrency cap (maximum in-flight requests)
- Per-request timeout
- Per-request latency, status code, and error recording
- Summary report: totals, average RPS, error rate, average/p50/p95/p99 latency, status-code counts, error-type counts
- CLI (
loadgenorpython -m loadgen) and a small Python API - Async test suite (pytest + pytest-asyncio) using httpx mock transports
Not implemented (planned / future):
- Distributed workers and test orchestration
- Request bodies (only method, URL, headers, and timeout are configurable)
- Retries, ramp-up, and graceful shutdown (signal handling)
- Live monitoring during a run; results are reported only at completion
- Persistent storage of results
Technology stack
| Technology | Role |
|---|---|
| Python >= 3.11 | Runtime |
| asyncio | Concurrency model (single event loop) |
| httpx >= 0.28 | Async HTTP client; connection pool sized to concurrency |
| pydantic >= 2.0 | Configuration parsing and validation |
| PyYAML >= 6.0 | YAML config parsing |
| pytest, pytest-asyncio | Test framework (dev dependency) |
Architecture
Request and data flow:
config.yaml
→ load_config() # YAML → EngineConfig (Pydantic)
→ LoadGenerator.run()
→ httpx.AsyncClient # shared client, pool limit = concurrency
→ Worker.run()
→ RateLimiter.acquire() # one slot every 1/rate seconds
→ asyncio.create_task(_execute_one)
→ semaphore # at most `concurrency` in flight
→ client.request() # HTTP request to target
→ Metrics.record() # RequestSample(latency, status | error)
→ gather(pending) # drain in-flight requests
→ Metrics.summary(elapsed) # totals, RPS, percentiles
→ Summary.render() # text report to stdout
Key units:
RateLimitercontrols launch cadence (rate).- The
asyncio.Semaphoreplus the httpx connection pool cap in-flight requests (concurrency). RequestSampleis the only data unit between the target and the report.
Prerequisites
- Python 3.11 or newer
- pip
Installation
Install from PyPI
pip install hailstorm-loadgen
Install from source
Clone the Hailstorm repository:
git clone https://github.com/karunakar78/hailstorm.git
cd hailstorm/loadgen
Install in editable mode:
pip install -e ".[dev]"
The dev extra installs pytest and pytest-asyncio for the test suite.
Configuration
The engine reads a YAML file (--config defaults to config.yaml):
target:
url: "http://localhost:8000/test" # Target endpoint (required)
method: "GET" # HTTP method (default: GET; uppercased)
headers: {} # Optional request headers
load:
duration: 30 # Test duration in seconds (required, > 0)
rate: 10 # Target requests per second (required, > 0)
concurrency: 5 # Max in-flight requests (required, >= 1)
request:
timeout: 5 # Per-request timeout in seconds (default: 5.0)
The request section is optional; all of its fields have defaults.
Validation is fail-fast: invalid values (for example duration <= 0, rate <= 0, concurrency < 1) raise a ValidationError before any request is sent.
Running
cd loadgen
loadgen --config config.yaml
or without the console script:
python -m loadgen --config config.yaml
The report is printed to stdout after the run:
Duration: 2.1 s
Total requests: 20
Average RPS: 9.5
Successful: 20
Failed: 0
Error rate: 0.0%
Latency:
avg: 7.2 ms
p50: 4.7 ms
p95: 18.0 ms
p99: 42.1 ms
Status codes:
200: 20
Note: the engine waits for in-flight requests to finish after the deadline, so the reported duration can slightly exceed the configured duration.
Python API
import asyncio
from loadgen import LoadGenerator, load_config
config = load_config("config.yaml")
summary = asyncio.run(LoadGenerator(config).run())
print(summary.render())
LoadGenerator also accepts an optional httpx.AsyncClient for dependency injection (used by the tests with httpx.MockTransport).
Testing
cd loadgen
pytest
The suite uses asyncio_mode = "auto" (configured in pyproject.toml) and httpx.MockTransport to exercise the engine without network access. Last observed run: 12 passed (pytest 9.1.1, pytest-asyncio 1.4.0, Python 3.12.6).
Project structure
loadgen/
├── config.yaml # Example configuration
├── pyproject.toml # Package metadata, dependencies, entry point, pytest config
├── src/loadgen/
│ ├── __init__.py # Public API re-exports
│ ├── __main__.py # python -m loadgen entry point
│ ├── cli.py # argparse CLI (--config), runs engine, prints report
│ ├── config.py # Pydantic config models and load_config()
│ ├── engine.py # LoadGenerator: client setup, run, summary
│ ├── metrics.py # RequestSample, Metrics, Summary, percentile calculation
│ ├── rate_limiter.py # Fixed-rate slot scheduler
│ └── worker.py # Scheduler loop, concurrency semaphore, request execution
└── tests/
├── test_config.py # Config loading, defaults, validation
├── test_engine.py # End-to-end runs against mock transports
├── test_metrics.py # Aggregation and percentile math
└── test_rate_limiter.py # Pacing accuracy
Design decisions
- Fixed-rate scheduling, not a token bucket. Each
acquire()advances a slot counter by1/rateon a monotonic clock. If a slot is missed (busy event loop), the delay is clamped to zero, producing a short catch-up burst; this keeps the aggregate rate on schedule instead of silently under-shooting the target RPS. - Rate and concurrency are independent knobs. Tasks are spawned at the configured rate regardless of response times; the semaphore (plus the httpx pool limit) is the actual in-flight cap. Raising
ratewithoutconcurrencydeepens the queue; raisingconcurrencylets the engine sustain the rate against a slower target. - One shared HTTP client. A single
httpx.AsyncClientwithmax_connectionsandmax_keepalive_connectionsset toconcurrency, so at most that many sockets exist at once. - Fail-fast validation. Configuration is parsed and validated before any socket is opened.
- Drain before reporting. In-flight requests are awaited in a
finallyblock, so the summary includes every launched request. - Errors are samples, not run failures. Timeouts and connection errors are recorded as samples with the exception type; the run continues and there are no retries.
- Aggregate at the end. Samples accumulate in a lock-protected list and are summarized once, keeping the hot path simple.
Known limitations
- Single-process, single machine; no distributed workers.
- All samples are held in memory until the run ends, which caps very long tests.
- No request body support;
targetaccepts onlyurl,method, andheaders. - No retries, ramp-up, or signal handling (interrupting the process does not produce a partial report).
- No live metrics during the run; the report is printed only at completion.
Metadata
Release files for hailstorm-loadgen 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| hailstorm_loadgen-0.1.0.tar.gz | 10.6 kB | Without provenance | Details for hailstorm_loadgen-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| hailstorm_loadgen-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for hailstorm_loadgen-0.1.0-py3-none-any.whl |
Total release size: 21.4 kB
Release files / hailstorm_loadgen-0.1.0.tar.gz
| Download URL | hailstorm_loadgen-0.1.0.tar.gz |
|---|---|
| Size | 10.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b49235f16c529272aaa0fcc80f6b303df8cdea4e7a9dc5f8f214d9a683d24ca8
|
|
BLAKE2b-256 checksum How to use checksums |
459c0764f227a6e2e7b44e2f4cd7fefdb8174a8259f0db7cd06d9b9bdf558761
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.6
|
Release files / hailstorm_loadgen-0.1.0-py3-none-any.whl
| Download URL | hailstorm_loadgen-0.1.0-py3-none-any.whl |
|---|---|
| Size | 10.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
36bb996059f9f6f040cbf985d2173866c6d105dcd35d3fa97cdf0d41fef58463
|
|
BLAKE2b-256 checksum How to use checksums |
4ca95ffd8d342aec1f8e2be472150bb790358256c069cf0f5fb9ee8dd3e1cd4a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.6
|
Security for hailstorm-loadgen 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.