Skip to content

Commit f3be219

Browse files
committed
set auto vaccum False, add fail_if_requests_timedout_in_last_x_seconds_is_more_than_y
Signed-off-by: Praneeth Bedapudi <[email protected]>
1 parent 106f33a commit f3be219

File tree

4 files changed

+58
-6
lines changed

4 files changed

+58
-6
lines changed

fastdeploy/_loop.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ def fetch_batch(
132132
# finished collecting batch
133133
break
134134

135+
_utils.logger.info(
136+
f"Fetched batch {[v for v in unique_id_wise_input_count.values()]}"
137+
)
135138
return unique_id_wise_input_count, input_batch
136139

137140

@@ -217,7 +220,7 @@ def start_loop(
217220
query={
218221
"$and": [
219222
{"-1.predicted_at": {"$gt": 0}},
220-
{"-1.predicted_at": {"$lt": time.time() - 30}},
223+
{"-1.predicted_at": {"$lt": time.time() - 40}},
221224
]
222225
},
223226
)

fastdeploy/_rest.py

+22-3
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def on_post(self, req, resp):
168168
class PrometheusMetrics(object):
169169
def on_get(self, req, resp):
170170
_LAST_X_SECONDS = int(
171-
req.params.get("last_x_seconds", int(os.getenv("LAST_X_SECONDS", 5)))
171+
req.params.get("last_x_seconds", int(os.getenv("LAST_X_SECONDS", 30)))
172172
)
173173
CURRENT_TIME = time.time()
174174
LAST_X_SECONDS = time.time() - _LAST_X_SECONDS
@@ -325,6 +325,12 @@ def on_get(self, req, resp):
325325
"fail_if_up_time_more_than_x_seconds", None
326326
)
327327

328+
fail_if_requests_timedout_in_last_x_seconds_is_more_than_y_param = (
329+
req.params.get(
330+
"fail_if_requests_timedout_in_last_x_seconds_is_more_than_y", None
331+
)
332+
)
333+
328334
is_predictor_is_up_param = req.params.get("is_predictor_is_up", None)
329335

330336
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):
342348
resp.media = {
343349
"reason": f"More than {y}% requests failed in last {x} seconds"
344350
}
345-
return
351+
return
346352

347353
elif fail_if_requests_older_than_x_seconds_pending_param:
348354
if _utils.check_if_requests_older_than_x_seconds_pending(
@@ -352,7 +358,7 @@ def on_get(self, req, resp):
352358
resp.media = {
353359
"reason": f"Requests older than {fail_if_requests_older_than_x_seconds_pending_param} seconds are pending"
354360
}
355-
return
361+
return
356362

357363
elif fail_if_up_time_more_than_x_seconds_param:
358364
if time.time() - Infer.started_at_time > int(
@@ -362,6 +368,19 @@ def on_get(self, req, resp):
362368
resp.media = {
363369
"reason": f"Up time more than {fail_if_up_time_more_than_x_seconds_param} seconds"
364370
}
371+
return
372+
373+
elif fail_if_requests_timedout_in_last_x_seconds_is_more_than_y_param:
374+
(
375+
x,
376+
y,
377+
) = fail_if_requests_timedout_in_last_x_seconds_is_more_than_y_param.split(
378+
","
379+
)
380+
x, y = int(x), int(y)
381+
if _utils.check_if_requests_timedout_in_last_x_seconds_is_more_than_y(x, y):
382+
resp.status = falcon.HTTP_503
383+
return
365384

366385
resp.status = falcon.HTTP_200
367386
resp.media = {"status": "ok"}

fastdeploy/_utils.py

+30
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
**{f"{_}.predicted_in_batch_of": "number" for _ in PREDICTOR_SEQUENCE_TO_FILES},
8989
},
9090
db_path=os.path.join("fastdeploy_dbs", f"main_index.db"),
91+
auto_vacuum=False,
9192
)
9293

9394
# for setting timedout_in_queue
@@ -176,6 +177,35 @@ def calculate_optimum_batch_sizes(
176177
return max_batch_size, time_per_example
177178

178179

180+
def check_if_requests_timedout_in_last_x_seconds_is_more_than_y(
181+
last_x_seconds, max_percentage_of_timedout_requests
182+
):
183+
time_before_x_seconds = time.time() - last_x_seconds
184+
requests_received_in_last_x_seconds = MAIN_INDEX.count(
185+
query={"-1.received_at": {"$gte": time_before_x_seconds}}
186+
)
187+
188+
requests_timedout_in_last_x_seconds = MAIN_INDEX.count(
189+
query={
190+
"-1.received_at": {"$gte": time_before_x_seconds},
191+
"timedout_in_queue": True,
192+
}
193+
)
194+
195+
if requests_received_in_last_x_seconds == 0:
196+
return False
197+
198+
logger.warning(
199+
f"Requests timedout in last {last_x_seconds} seconds: {requests_timedout_in_last_x_seconds}/{requests_received_in_last_x_seconds}"
200+
)
201+
202+
if (
203+
requests_timedout_in_last_x_seconds / requests_received_in_last_x_seconds
204+
) * 100 >= max_percentage_of_timedout_requests:
205+
return True
206+
return False
207+
208+
179209
def check_if_percentage_of_requests_failed_in_last_x_seconds_is_more_than_y(
180210
last_x_seconds, max_percentage_of_failed_requests
181211
):

setup.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
1919
AUTHOR = "BEDAPUDI PRANEETH"
2020
REQUIRES_PYTHON = ">=3.6.0"
21-
VERSION = "3.0.28"
21+
VERSION = "3.0.30"
2222

2323
# What packages are required for this module to be executed?
24-
REQUIRED = ["falcon", "liteindex==0.0.3.2.dev4", "zstandard", "gunicorn[gevent]", "msgpack"]
24+
REQUIRED = ["falcon", "liteindex==0.0.3.2.dev6", "zstandard", "gunicorn[gevent]", "msgpack"]
2525

2626
# What packages are optional?
2727
EXTRAS = {

0 commit comments

Comments
 (0)