mirror of
https://github.com/BerriAI/litellm.git
synced 2026-08-28 05:25:59 +00:00
fix: add auth headers and empty latencies guard to benchmark script
This commit is contained in:
parent
8244ad1f0e
commit
95d9514054
1 changed files with 14 additions and 1 deletions
|
|
@ -16,12 +16,17 @@ REQUEST_BODY = {
|
|||
"user": "new_user",
|
||||
}
|
||||
|
||||
HEADERS = {
|
||||
"Authorization": "Bearer sk-1234",
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
|
||||
|
||||
async def send_request(session, url, semaphore):
|
||||
async with semaphore:
|
||||
start = time.perf_counter()
|
||||
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()
|
||||
elapsed = time.perf_counter() - start
|
||||
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]
|
||||
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()
|
||||
n = len(latencies)
|
||||
mean = statistics.mean(latencies) * 1000
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue