fix: add auth headers and empty latencies guard to benchmark script
This commit is contained in:
parent
8244ad1f0e
commit
95d9514054
@ -16,12 +16,17 @@ REQUEST_BODY = {
|
|||||||
"user": "new_user",
|
"user": "new_user",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HEADERS = {
|
||||||
|
"Authorization": "Bearer sk-1234",
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
async def send_request(session, url, semaphore):
|
async def send_request(session, url, semaphore):
|
||||||
async with semaphore:
|
async with semaphore:
|
||||||
start = time.perf_counter()
|
start = time.perf_counter()
|
||||||
try:
|
try:
|
||||||
async with session.post(url, json=REQUEST_BODY) as resp:
|
async with session.post(url, json=REQUEST_BODY, headers=HEADERS) as resp:
|
||||||
await resp.read()
|
await resp.read()
|
||||||
elapsed = time.perf_counter() - start
|
elapsed = time.perf_counter() - start
|
||||||
return elapsed if resp.status == 200 else None
|
return elapsed if resp.status == 200 else None
|
||||||
@ -50,6 +55,14 @@ async def run_benchmark(url, n_requests, max_concurrent):
|
|||||||
latencies = [r for r in results if r is not None]
|
latencies = [r for r in results if r is not None]
|
||||||
failures = sum(1 for r in results if r is None)
|
failures = sum(1 for r in results if r is None)
|
||||||
|
|
||||||
|
if not latencies:
|
||||||
|
return {
|
||||||
|
"mean": 0, "p50": 0, "p95": 0, "p99": 0,
|
||||||
|
"throughput": 0, "failures": n_requests,
|
||||||
|
"wall_time": wall_elapsed, "n_requests": n_requests,
|
||||||
|
"max_concurrent": max_concurrent, "latencies": [],
|
||||||
|
}
|
||||||
|
|
||||||
latencies.sort()
|
latencies.sort()
|
||||||
n = len(latencies)
|
n = len(latencies)
|
||||||
mean = statistics.mean(latencies) * 1000
|
mean = statistics.mean(latencies) * 1000
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user