Skip to content

Commit

Permalink
set auto vaccum False, add fail_if_requests_timedout_in_last_x_second…
Browse files Browse the repository at this point in the history
…s_is_more_than_y

Signed-off-by: Praneeth Bedapudi <[email protected]>
  • Loading branch information
bedapudi6788 committed Nov 7, 2024
1 parent 106f33a commit f3be219
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 6 deletions.
5 changes: 4 additions & 1 deletion fastdeploy/_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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}},
]
},
)
Expand Down
25 changes: 22 additions & 3 deletions fastdeploy/_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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"}
Expand Down
30 changes: 30 additions & 0 deletions fastdeploy/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
):
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
EMAIL = "[email protected]"
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 = {
Expand Down

0 comments on commit f3be219

Please sign in to comment.