Skip to content

Commit 7dc6a95

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

2 files changed

Lines changed: 41 additions & 2 deletions

File tree

src/vllm_router/service_discovery.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ class EndpointInfo:
5656
# Model label
5757
model_label: str
5858

59+
# Endpoint's sleep status
60+
sleep: bool
61+
5962
# Pod name
6063
pod_name: Optional[str] = None
6164

@@ -260,6 +263,7 @@ def get_endpoint_info(self) -> List[EndpointInfo]:
260263
url=url,
261264
model_names=[model], # Convert single model to list
262265
Id=self.engines_id[i],
266+
sleep=False,
263267
added_timestamp=self.added_timestamp,
264268
model_label=model_label,
265269
model_info=self._get_model_info(model),
@@ -340,6 +344,33 @@ def _check_pod_ready(container_statuses):
340344
ready_count = sum(1 for status in container_statuses if status.ready)
341345
return ready_count == len(container_statuses)
342346

347+
def _get_engine_sleep_status(self, pod_ip) -> Optional[bool]:
348+
"""
349+
Get the engine sleeping status by querying the engine's
350+
'/is_sleeping' endpoint.
351+
352+
Args:
353+
pod_ip: the IP address of the pod running the engine
354+
355+
Returns:
356+
the sleep status of the target engine
357+
"""
358+
url = f"http://{pod_ip}:{self.port}/is_sleeping"
359+
sleep = False
360+
try:
361+
headers = None
362+
if VLLM_API_KEY := os.getenv("VLLM_API_KEY"):
363+
logger.info(f"Using vllm server authentication")
364+
headers = {"Authorization": f"Bearer {VLLM_API_KEY}"}
365+
response = requests.get(url, headers=headers)
366+
response.raise_for_status()
367+
sleep = response.json()["is_sleeping"]
368+
except Exception as e:
369+
logger.warning(
370+
f"Failed to get the sleep status for engine at {url} - sleep status is set to `False`: {e}"
371+
)
372+
return sleep
373+
343374
def _get_model_names(self, pod_ip) -> List[str]:
344375
"""
345376
Get the model names of the serving engine pod by querying the pod's
@@ -478,6 +509,7 @@ def _add_engine(
478509
added_timestamp=int(time.time()),
479510
Id=str(uuid.uuid5(uuid.NAMESPACE_DNS, engine_name)),
480511
model_label=model_label,
512+
sleep=self._get_engine_sleep_status(engine_ip),
481513
pod_name=engine_name,
482514
namespace=self.namespace,
483515
)

src/vllm_router/services/request_service/request.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,15 +221,22 @@ async def route_general_request(
221221
update_content_length(request, request_body)
222222

223223
if not request_endpoint:
224-
endpoints = list(filter(lambda x: requested_model in x.model_names, endpoints))
224+
endpoints = list(
225+
filter(
226+
lambda x: requested_model in x.model_names and x.sleep == False,
227+
endpoints,
228+
)
229+
)
225230
engine_stats = request.app.state.engine_stats_scraper.get_engine_stats()
226231
request_stats = request.app.state.request_stats_monitor.get_request_stats(
227232
time.time()
228233
)
229234
else:
230235
endpoints = list(
231236
filter(
232-
lambda x: requested_model in x.model_names and x.Id == request_endpoint,
237+
lambda x: requested_model in x.model_names
238+
and x.Id == request_endpoint
239+
and x.sleep == False,
233240
endpoints,
234241
)
235242
)

0 commit comments

Comments
 (0)