Skip to content

Commit 2ff0811

Browse files
committed
Adding check for engine sleeping status at service_discovery
Signed-off-by: Braulio Dumba <Braulio.Dumba@ibm.com>
1 parent a7fe3bc commit 2ff0811

2 files changed

Lines changed: 43 additions & 3 deletions

File tree

src/vllm_router/service_discovery.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ class EndpointInfo:
4949
# Model label
5050
model_label: str
5151

52+
# Endpoint's sleep status
53+
sleep: bool
54+
5255

5356
class ServiceDiscovery(metaclass=abc.ABCMeta):
5457
@abc.abstractmethod
@@ -103,7 +106,7 @@ def get_endpoint_info(self) -> List[EndpointInfo]:
103106
"""
104107

105108
endpoint_infos = [
106-
EndpointInfo(url, model, self.added_timestamp, model_label)
109+
EndpointInfo(url, model, self.added_timestamp, model_label, False)
107110
for url, model, model_label in zip(
108111
self.urls, self.models, self.model_labels
109112
)
@@ -157,6 +160,33 @@ def _check_pod_ready(container_statuses):
157160
ready_count = sum(1 for status in container_statuses if status.ready)
158161
return ready_count == len(container_statuses)
159162

163+
def _get_engine_sleep_status(self, pod_ip) -> Optional[bool]:
164+
"""
165+
Get the engine sleeping status by querying the engine's
166+
'/is_sleeping' endpoint.
167+
168+
Args:
169+
pod_ip: the IP address of the pod running the engine
170+
171+
Returns:
172+
the sleep status of the engine
173+
"""
174+
url = f"http://{pod_ip}:{self.port}/is_sleeping"
175+
sleep = False
176+
try:
177+
headers = None
178+
if VLLM_API_KEY := os.getenv("VLLM_API_KEY"):
179+
logger.info(f"Using vllm server authentication")
180+
headers = {"Authorization": f"Bearer {VLLM_API_KEY}"}
181+
response = requests.get(url, headers=headers)
182+
response.raise_for_status()
183+
sleep = response.json()["is_sleeping"]
184+
except Exception as e:
185+
logger.error(f"Failed to get the sleep status for engine at {url}: {e}")
186+
return None
187+
188+
return sleep
189+
160190
def _get_model_name(self, pod_ip) -> Optional[str]:
161191
"""
162192
Get the model name of the serving engine pod by querying the pod's
@@ -238,12 +268,14 @@ def _add_engine(
238268
f"Discovered new serving engine {engine_name} at "
239269
f"{engine_ip}, running model: {model_name}"
240270
)
271+
241272
with self.available_engines_lock:
242273
self.available_engines[engine_name] = EndpointInfo(
243274
url=f"http://{engine_ip}:{self.port}",
244275
model_name=model_name,
245276
added_timestamp=int(time.time()),
246277
model_label=model_label,
278+
sleep=self._get_engine_sleep_status(engine_ip),
247279
)
248280

249281
def _delete_engine(self, engine_name: str):

src/vllm_router/services/request_service/request.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,11 @@ async def route_general_request(
217217
request_body = replace_model_in_request_body(request_json, requested_model)
218218
update_content_length(request, request_body)
219219

220-
endpoints = list(filter(lambda x: x.model_name == requested_model, endpoints))
220+
endpoints = list(
221+
filter(
222+
lambda x: x.model_name == requested_model and x.sleep == False, endpoints
223+
)
224+
)
221225
if not endpoints:
222226
return JSONResponse(
223227
status_code=400, content={"error": f"Model {requested_model} not found."}
@@ -286,7 +290,11 @@ async def route_disaggregated_prefill_request(
286290
time.time()
287291
)
288292

289-
endpoints = list(filter(lambda x: x.model_name == requested_model, endpoints))
293+
endpoints = list(
294+
filter(
295+
lambda x: x.model_name == requested_model and x.sleep == False, endpoints
296+
)
297+
)
290298
if not endpoints:
291299
return JSONResponse(
292300
status_code=400, content={"error": f"Model {requested_model} not found."}

0 commit comments

Comments
 (0)