From f3be219d7c01124bc64e2c9a7720fc973480d422 Mon Sep 17 00:00:00 2001 From: Praneeth Bedapudi Date: Thu, 7 Nov 2024 10:52:57 +0530 Subject: [PATCH] set auto vaccum False, add fail_if_requests_timedout_in_last_x_seconds_is_more_than_y Signed-off-by: Praneeth Bedapudi --- fastdeploy/_loop.py | 5 ++++- fastdeploy/_rest.py | 25 ++++++++++++++++++++++--- fastdeploy/_utils.py | 30 ++++++++++++++++++++++++++++++ setup.py | 4 ++-- 4 files changed, 58 insertions(+), 6 deletions(-) diff --git a/fastdeploy/_loop.py b/fastdeploy/_loop.py index 27b2b5a..4aca690 100644 --- a/fastdeploy/_loop.py +++ b/fastdeploy/_loop.py @@ -132,6 +132,9 @@ def fetch_batch( # finished collecting batch break + _utils.logger.info( + f"Fetched batch {[v for v in unique_id_wise_input_count.values()]}" + ) return unique_id_wise_input_count, input_batch @@ -217,7 +220,7 @@ def start_loop( query={ "$and": [ {"-1.predicted_at": {"$gt": 0}}, - {"-1.predicted_at": {"$lt": time.time() - 30}}, + {"-1.predicted_at": {"$lt": time.time() - 40}}, ] }, ) diff --git a/fastdeploy/_rest.py b/fastdeploy/_rest.py index 56a0f6a..072cddf 100644 --- a/fastdeploy/_rest.py +++ b/fastdeploy/_rest.py @@ -168,7 +168,7 @@ def on_post(self, req, resp): class PrometheusMetrics(object): def on_get(self, req, resp): _LAST_X_SECONDS = int( - req.params.get("last_x_seconds", int(os.getenv("LAST_X_SECONDS", 5))) + req.params.get("last_x_seconds", int(os.getenv("LAST_X_SECONDS", 30))) ) CURRENT_TIME = time.time() LAST_X_SECONDS = time.time() - _LAST_X_SECONDS @@ -325,6 +325,12 @@ def on_get(self, req, resp): "fail_if_up_time_more_than_x_seconds", None ) + fail_if_requests_timedout_in_last_x_seconds_is_more_than_y_param = ( + req.params.get( + "fail_if_requests_timedout_in_last_x_seconds_is_more_than_y", None + ) + ) + is_predictor_is_up_param = req.params.get("is_predictor_is_up", None) if fail_if_percentage_of_requests_failed_in_last_x_seconds_is_more_than_y_param: @@ -342,7 +348,7 @@ def on_get(self, req, resp): resp.media = { "reason": f"More than {y}% requests failed in last {x} seconds" } - return + return elif fail_if_requests_older_than_x_seconds_pending_param: if _utils.check_if_requests_older_than_x_seconds_pending( @@ -352,7 +358,7 @@ def on_get(self, req, resp): resp.media = { "reason": f"Requests older than {fail_if_requests_older_than_x_seconds_pending_param} seconds are pending" } - return + return elif fail_if_up_time_more_than_x_seconds_param: if time.time() - Infer.started_at_time > int( @@ -362,6 +368,19 @@ def on_get(self, req, resp): resp.media = { "reason": f"Up time more than {fail_if_up_time_more_than_x_seconds_param} seconds" } + return + + elif fail_if_requests_timedout_in_last_x_seconds_is_more_than_y_param: + ( + x, + y, + ) = fail_if_requests_timedout_in_last_x_seconds_is_more_than_y_param.split( + "," + ) + x, y = int(x), int(y) + if _utils.check_if_requests_timedout_in_last_x_seconds_is_more_than_y(x, y): + resp.status = falcon.HTTP_503 + return resp.status = falcon.HTTP_200 resp.media = {"status": "ok"} diff --git a/fastdeploy/_utils.py b/fastdeploy/_utils.py index 1617a83..1e2ed78 100644 --- a/fastdeploy/_utils.py +++ b/fastdeploy/_utils.py @@ -88,6 +88,7 @@ **{f"{_}.predicted_in_batch_of": "number" for _ in PREDICTOR_SEQUENCE_TO_FILES}, }, db_path=os.path.join("fastdeploy_dbs", f"main_index.db"), + auto_vacuum=False, ) # for setting timedout_in_queue @@ -176,6 +177,35 @@ def calculate_optimum_batch_sizes( return max_batch_size, time_per_example +def check_if_requests_timedout_in_last_x_seconds_is_more_than_y( + last_x_seconds, max_percentage_of_timedout_requests +): + time_before_x_seconds = time.time() - last_x_seconds + requests_received_in_last_x_seconds = MAIN_INDEX.count( + query={"-1.received_at": {"$gte": time_before_x_seconds}} + ) + + requests_timedout_in_last_x_seconds = MAIN_INDEX.count( + query={ + "-1.received_at": {"$gte": time_before_x_seconds}, + "timedout_in_queue": True, + } + ) + + if requests_received_in_last_x_seconds == 0: + return False + + logger.warning( + f"Requests timedout in last {last_x_seconds} seconds: {requests_timedout_in_last_x_seconds}/{requests_received_in_last_x_seconds}" + ) + + if ( + requests_timedout_in_last_x_seconds / requests_received_in_last_x_seconds + ) * 100 >= max_percentage_of_timedout_requests: + return True + return False + + def check_if_percentage_of_requests_failed_in_last_x_seconds_is_more_than_y( last_x_seconds, max_percentage_of_failed_requests ): diff --git a/setup.py b/setup.py index bbbc7c8..74e9a2d 100644 --- a/setup.py +++ b/setup.py @@ -18,10 +18,10 @@ EMAIL = "praneeth@bpraneeth.com" AUTHOR = "BEDAPUDI PRANEETH" REQUIRES_PYTHON = ">=3.6.0" -VERSION = "3.0.28" +VERSION = "3.0.30" # What packages are required for this module to be executed? -REQUIRED = ["falcon", "liteindex==0.0.3.2.dev4", "zstandard", "gunicorn[gevent]", "msgpack"] +REQUIRED = ["falcon", "liteindex==0.0.3.2.dev6", "zstandard", "gunicorn[gevent]", "msgpack"] # What packages are optional? EXTRAS = {