[Logs] DP Supervisor Log Improvement (#48278)
Signed-off-by: Robert Shaw <robertgshaw2-redhat@ip-172-31-18-125.us-east-2.compute.internal> Co-authored-by: Robert Shaw <robertgshaw2-redhat@ip-172-31-18-125.us-east-2.compute.internal>
This commit is contained in:
co-authored by
Robert Shaw
parent
04d553f390
commit
3d99b0499a
@@ -283,14 +283,46 @@ class DPSupervisor:
|
||||
|
||||
async def run(self) -> None:
|
||||
loop = asyncio.get_running_loop()
|
||||
decorate_logs("DPSupervisor")
|
||||
|
||||
# K8s sends SIGTERM for shutdown - begin graceful termination.
|
||||
for sig in (signal.SIGTERM, signal.SIGINT):
|
||||
loop.add_signal_handler(sig, partial(self._handle_signal, sig))
|
||||
|
||||
# Launch DPSupervisor Server.
|
||||
supervisor_server: uvicorn.Server | None = None
|
||||
supervisor_server_task: asyncio.Task[None] | None = None
|
||||
try:
|
||||
# Launch vLLM DP Servers and begin monitoring them.
|
||||
self._start_children()
|
||||
monitor_task = asyncio.create_task(
|
||||
self._monitor_children(), name="dp-monitor"
|
||||
)
|
||||
|
||||
# Only start the DPSupervisor server once the vLLM DP Servers are
|
||||
# ready. This avoids the supervisor /health endpoint returning 503
|
||||
# to external load balancer probes while the engines initialize.
|
||||
await self._wait_until_ready(monitor_task)
|
||||
if self.is_ready and not monitor_task.done():
|
||||
supervisor_server, supervisor_server_task = await self._start_server()
|
||||
|
||||
await monitor_task
|
||||
finally:
|
||||
self._is_ready = False
|
||||
await self._shutdown_children()
|
||||
|
||||
# Shutdown the DP Supervisor server.
|
||||
if supervisor_server is not None and supervisor_server_task is not None:
|
||||
supervisor_server.should_exit = True
|
||||
await supervisor_server_task
|
||||
|
||||
async def _start_server(self) -> tuple[uvicorn.Server, asyncio.Task[None]]:
|
||||
"""
|
||||
Launch the DPSupervisor HTTP server.
|
||||
|
||||
Called only after the vLLM DP Servers are ready so that /health does
|
||||
not return 503 to external probes while the engines are initializing.
|
||||
"""
|
||||
app = _build_dp_supervisor_app(self)
|
||||
decorate_logs("DPSupervisor")
|
||||
host = self.args.host or "0.0.0.0"
|
||||
config = uvicorn.Config(
|
||||
app,
|
||||
@@ -319,18 +351,20 @@ class DPSupervisor:
|
||||
raise RuntimeError("DPSupervisor exited before startup.")
|
||||
await asyncio.sleep(0.05)
|
||||
logger.info("Started DPSupervisor on %s:%d", host, self.supervisor_port)
|
||||
return supervisor_server, supervisor_server_task
|
||||
|
||||
# Launch and Monitor vLLM Server Processes.
|
||||
try:
|
||||
self._start_children()
|
||||
await self._monitor_children()
|
||||
finally:
|
||||
self._is_ready = False
|
||||
await self._shutdown_children()
|
||||
async def _wait_until_ready(self, monitor_task: asyncio.Task[None]) -> None:
|
||||
"""
|
||||
Block until the vLLM DP Servers are ready or shutdown is triggered.
|
||||
|
||||
# Shutdown the DP Supervisor server.
|
||||
supervisor_server.should_exit = True
|
||||
await supervisor_server_task
|
||||
Returns early if monitoring stops (e.g. a DP Server dies during
|
||||
startup), in which case the supervisor server is never started.
|
||||
"""
|
||||
logger.info("Waiting for vLLM DP Servers to become ready.")
|
||||
while not self._is_ready and not self._shutdown_event.is_set():
|
||||
if monitor_task.done():
|
||||
return
|
||||
await asyncio.sleep(0.05)
|
||||
|
||||
def _handle_signal(self, signum: int) -> None:
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user