don't healthcheck endpoints until model is loaded and benchmarks have run

This commit is contained in:
Nader Arbabian
2025-06-11 15:25:57 -07:00
committed by Nader Arbabian
parent 0ab9a13a46
commit 9ebf1924ea
+22 -17
View File
@@ -60,6 +60,7 @@ class Backend:
self.metrics = Metrics() self.metrics = Metrics()
self._total_pubkey_fetch_errors = 0 self._total_pubkey_fetch_errors = 0
self._pubkey = self._fetch_pubkey() self._pubkey = self._fetch_pubkey()
self.__start_healthcheck: bool = False
@property @property
def pubkey(self) -> Optional[RSA.RsaKey]: def pubkey(self) -> Optional[RSA.RsaKey]:
@@ -191,23 +192,26 @@ class Backend:
if health_check_url is None: if health_check_url is None:
log.debug("No healthcheck endpoint defined, skipping healthcheck") log.debug("No healthcheck endpoint defined, skipping healthcheck")
return return
await sleep(5) while True:
try: await sleep(10)
log.debug(f"Performing healthcheck on {health_check_url}") if self.__start_healthcheck is False:
async with self.session.get(health_check_url) as response: continue
if response.status == 200: try:
log.debug("Healthcheck successful") log.debug(f"Performing healthcheck on {health_check_url}")
elif response.status == 503: async with self.session.get(health_check_url) as response:
log.debug(f"Healthcheck failed with status: {response.status}") if response.status == 200:
self.backend_errored( log.debug("Healthcheck successful")
f"Healthcheck failed with status: {response.status}" elif response.status == 503:
) log.debug(f"Healthcheck failed with status: {response.status}")
else: self.backend_errored(
# endpoint not ready yet so bail f"Healthcheck failed with status: {response.status}"
log.debug(f"Healthcheck Endpoint not ready: {response.status}") )
except Exception as e: else:
log.debug(f"Healthcheck failed with exception: {e}") # endpoint not ready yet so bail
self.backend_errored(str(e)) log.debug(f"Healthcheck Endpoint not ready: {response.status}")
except Exception as e:
log.debug(f"Healthcheck failed with exception: {e}")
self.backend_errored(str(e))
async def _start_tracking(self) -> None: async def _start_tracking(self) -> None:
await gather( await gather(
@@ -331,6 +335,7 @@ class Backend:
await sleep(5) await sleep(5)
try: try:
max_throughput = await run_benchmark() max_throughput = await run_benchmark()
self.__start_healthcheck = True
self.metrics._model_loaded( self.metrics._model_loaded(
max_throughput=max_throughput, max_throughput=max_throughput,
) )