71 lines
2.0 KiB
Python
71 lines
2.0 KiB
Python
import asyncio
|
|
import time
|
|
|
|
import httpx
|
|
|
|
|
|
URL = "http://127.0.0.1:8899/v1/audio/transcriptions"
|
|
AUDIO_FILE = "/home/timur/Projects/TP_VOICE_REC/WAV_INPUT/in-2798088-89174593307-20260604-153517-1780569317.96149.WAV"
|
|
REQUESTS = 5
|
|
|
|
|
|
async def submit(client: httpx.AsyncClient, number: int):
|
|
started = time.perf_counter()
|
|
|
|
with open(AUDIO_FILE, "rb") as audio:
|
|
response = await client.post(
|
|
URL,
|
|
files={"file": ("speech.wav", audio, "audio/wav")},
|
|
data={"async_job": "true"},
|
|
)
|
|
|
|
response.raise_for_status()
|
|
job = response.json()
|
|
print(f"submitted {number}: {job['id']}")
|
|
return number, job["id"], started
|
|
|
|
|
|
async def wait_for_job(client: httpx.AsyncClient, number: int, job_id: str):
|
|
while True:
|
|
response = await client.get(
|
|
f"http://127.0.0.1:8899/v1/jobs/{job_id}"
|
|
)
|
|
response.raise_for_status()
|
|
job = response.json()
|
|
|
|
if job["status"] in {"succeeded", "failed"}:
|
|
print(
|
|
f"finished {number}: status={job['status']} "
|
|
f"started={job['started_at']} "
|
|
f"finished={job['finished_at']}"
|
|
)
|
|
return job
|
|
|
|
await asyncio.sleep(0.1)
|
|
|
|
|
|
async def main():
|
|
async with httpx.AsyncClient(timeout=300) as client:
|
|
submissions = await asyncio.gather(
|
|
*(submit(client, number) for number in range(REQUESTS))
|
|
)
|
|
|
|
jobs = await asyncio.gather(
|
|
*(
|
|
wait_for_job(client, number, job_id)
|
|
for number, job_id, _ in submissions
|
|
)
|
|
)
|
|
|
|
ordered = sorted(jobs, key=lambda job: job["started_at"])
|
|
|
|
for previous, current in zip(ordered, ordered[1:]):
|
|
assert previous["finished_at"] <= current["started_at"], (
|
|
"GPU jobs overlapped"
|
|
)
|
|
|
|
assert all(job["status"] == "succeeded" for job in jobs)
|
|
print("Verified: all requests succeeded without overlapping inference.")
|
|
|
|
|
|
asyncio.run(main()) |