Skip to content

Commit

Permalink
benchmark: Simplify by using nullcontext
Browse files Browse the repository at this point in the history
Signed-off-by: Russell Bryant <[email protected]>
  • Loading branch information
russellb committed Oct 16, 2024
1 parent 520b43f commit 6bb7eff
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions benchmarks/benchmark_serving.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import argparse
import asyncio
import base64
import contextlib
import io
import json
import os
Expand Down Expand Up @@ -450,15 +451,13 @@ async def benchmark(

pbar = None if disable_tqdm else tqdm(total=len(input_requests))

semaphore = asyncio.Semaphore(max_concurrency) if max_concurrency else None
semaphore = (asyncio.Semaphore(max_concurrency)
if max_concurrency else contextlib.nullcontext())

async def limited_request_func(request_func_input, pbar):
if semaphore:
async with semaphore:
return await request_func(
request_func_input=request_func_input, pbar=pbar)
return await request_func(request_func_input=request_func_input,
pbar=pbar)
async with semaphore:
return await request_func(request_func_input=request_func_input,
pbar=pbar)

benchmark_start_time = time.perf_counter()
tasks: List[asyncio.Task] = []
Expand Down

0 comments on commit 6bb7eff

Please sign in to comment.