Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions scripts/load_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import asyncio
import time
import httpx

API_BASE_URL = "http://localhost:8000/api/v1"

async def dispatch_single_task(client: httpx.AsyncClient, index: int):
payload = {
"task_name": "tasks.data_etl_pipeline",
"parameters": {"batch_id": index, "records": 500},
"priority": "normal"
}
start = time.perf_counter()
try:
resp = await client.post(f"{API_BASE_URL}/tasks/submit", json=payload, timeout=5.0)
duration_ms = (time.perf_counter() - start) * 1000
return resp.status_code, duration_ms
except Exception as e:
return 500, 0.0

async def run_benchmark(concurrency: int = 25, total_requests: int = 100):
print(f"Starting load test: {total_requests} requests with {concurrency} concurrent workers...")
async with httpx.AsyncClient() as client:
tasks = [dispatch_single_task(client, i) for i in range(total_requests)]
results = await asyncio.gather(*tasks)

successes = [d for status, d in results if status == 202]
print(f"Results: {len(successes)}/{total_requests} accepted")
if successes:
print(f"Avg latency: {sum(successes)/len(successes):.2f}ms")
print(f"Min latency: {min(successes):.2f}ms | Max: {max(successes):.2f}ms")

if __name__ == "__main__":
asyncio.run(run_benchmark())
Loading