Compare commits

...

1 Commits

Author SHA1 Message Date
Nader Arbabian eecefd1d52 for benchmarking, use concurrent requests 2025-08-11 12:17:09 -07:00
+31 -20
View File
@@ -280,41 +280,52 @@ class Backend:
return float(f.readline()) return float(f.readline())
except FileNotFoundError: except FileNotFoundError:
pass pass
max_throughput = 0
last_throughput = 0 log.debug("Initial run to trigger model loading...")
sum_throughput = 0
for run in range(self.benchmark_handler.benchmark_runs + 1):
start = time.time()
payload = self.benchmark_handler.make_benchmark_payload() payload = self.benchmark_handler.make_benchmark_payload()
res = await self.__call_api( await self.__call_api(handler=self.benchmark_handler, payload=payload)
handler=self.benchmark_handler, payload=payload
max_throughput = 0
sum_throughput = 0
concurrent_requests = 10 if self.allow_parallel_requests else 1
for run in range(1, self.benchmark_handler.benchmark_runs + 1):
start = time.time()
tasks = []
total_workload = 0
for _ in range(concurrent_requests):
payload = self.benchmark_handler.make_benchmark_payload()
total_workload += payload.count_workload()
tasks.append(
self.__call_api(handler=self.benchmark_handler, payload=payload)
) )
data = await res.json()
responses = await gather(*tasks)
time_elapsed = time.time() - start time_elapsed = time.time() - start
# first run triggers one-time loading of the model which is very slow, so we skip counting it
if run == 0: throughput = total_workload / time_elapsed
continue sum_throughput += throughput
else: max_throughput = max(max_throughput, throughput)
workload = payload.count_workload()
last_throughput = workload / time_elapsed # Log results for debugging
sum_throughput += last_throughput
max_throughput = max(max_throughput, last_throughput)
log.debug( log.debug(
"\n".join( "\n".join(
[ [
"#" * 60, "#" * 60,
f"Run: {run}, workload: {workload} time_elapsed: {time_elapsed}, throughput: {last_throughput}", f"Run: {run}, concurrent_requests: {concurrent_requests}",
"", f"Total workload: {total_workload}, time_elapsed: {time_elapsed}s",
f"response: {data}", f"Throughput: {throughput} workload/s",
f"Successful responses: {len([r for r in responses if r.status == 200])}",
"#" * 60, "#" * 60,
] ]
) )
) )
average_throughput = sum_throughput / self.benchmark_handler.benchmark_runs average_throughput = sum_throughput / self.benchmark_handler.benchmark_runs
log.debug( log.debug(
f"benchmark result: avg {average_throughput} workload per second, max {max_throughput}" f"benchmark result: avg {average_throughput} workload per second, max {max_throughput}"
) )
# save max_throughput so we don't have to run benchmark again on restart of cold instances
with open(BENCHMARK_INDICATOR_FILE, "w") as f: with open(BENCHMARK_INDICATOR_FILE, "w") as f:
f.write(str(max_throughput)) f.write(str(max_throughput))
return max_throughput return max_throughput