Skip to content

Commit 186a213

Browse files
committed
reduce idle cpu usage
Signed-off-by: Praneeth Bedapudi <[email protected]>
1 parent 3796ecf commit 186a213

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

fastdeploy/_loop.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ def fetch_batch(
8585
input_batch = []
8686
current_batch_length = 0
8787
batch_collection_started_at = time.time()
88+
last_input_received_at = time.time()
8889

8990
while current_batch_length < optimal_batch_size:
9091
to_process = main_index.search(
@@ -106,15 +107,17 @@ def fetch_batch(
106107

107108
for unique_id, data in to_process.items():
108109
outputs = data[f"{predictor_sequence - 1}.outputs"]
109-
110110
input_count = len(outputs)
111-
112111
unique_id_wise_input_count[unique_id] = input_count
113112
input_batch.extend(outputs)
114113
current_batch_length += input_count
114+
last_input_received_at = time.time()
115115

116116
if current_batch_length == 0:
117-
time.sleep(max_wait_time_for_batch_collection / 2)
117+
if time.time() - last_input_received_at > 5:
118+
time.sleep(0.05)
119+
else:
120+
time.sleep(max_wait_time_for_batch_collection / 2)
118121
continue
119122

120123
elif (

fastdeploy/_rest.py

+6
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def deregister_request(self, unique_id):
6363
self.pending_requests.pop(unique_id, None)
6464

6565
def _response_checker(self):
66+
last_input_received_at = time.time()
6667
while True:
6768
try:
6869
unique_ids = []
@@ -73,6 +74,11 @@ def _response_checker(self):
7374
unique_ids.append(uid)
7475
is_compresseds.append(data["is_compressed"])
7576
input_types.append(data["input_type"])
77+
last_input_received_at = data["timestamp"]
78+
79+
if not unique_ids and (time.time() - last_input_received_at) > 5:
80+
time.sleep(0.05)
81+
continue
7682

7783
if unique_ids:
7884
_utils.logger.debug(

fastdeploy/_utils.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,9 @@
114114
MAIN_INDEX.optimize_for_query(["timedout_in_queue"])
115115

116116

117-
GLOBAL_METRICS_INDEX = KVIndex(os.path.join("fastdeploy_dbs", f"global_metrics_index.db"))
117+
GLOBAL_METRICS_INDEX = KVIndex(
118+
os.path.join("fastdeploy_dbs", f"global_metrics_index.db")
119+
)
118120
GLOBAL_METRICS_INDEX["total_predictor_run_for_hours"] = 0
119121
GLOBAL_METRICS_INDEX["total_predictor_up_for_hours"] = 0
120122

setup.py

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

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

0 commit comments

Comments
 (0)