Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhance: fetch containers eagerly when sync containers #2262

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/ai/backend/agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -1265,10 +1265,17 @@ async def sync_container_lifecycles(self, interval: float) -> None:
own_kernels: dict[KernelId, ContainerId] = {}
terminated_kernels: dict[KernelId, ContainerLifecycleEvent] = {}

_containers = await self.enumerate_containers(DEAD_STATUS_SET | ACTIVE_STATUS_SET)

async with self.registry_lock:
try:
# Check if: there are dead containers
for kernel_id, container in await self.enumerate_containers(DEAD_STATUS_SET):
dead_containers = [
(kid, container)
for kid, container in _containers
if container.status in DEAD_STATUS_SET
]
for kernel_id, container in dead_containers:
if kernel_id in self.restarting_kernels:
continue
log.info(
Expand All @@ -1284,7 +1291,12 @@ async def sync_container_lifecycles(self, interval: float) -> None:
LifecycleEvent.CLEAN,
KernelLifecycleEventReason.SELF_TERMINATED,
)
for kernel_id, container in await self.enumerate_containers(ACTIVE_STATUS_SET):
alive_containers = [
(kid, container)
for kid, container in _containers
if container.status in ACTIVE_STATUS_SET
]
for kernel_id, container in alive_containers:
alive_kernels[kernel_id] = container.id
session_id = SessionId(UUID(container.labels["ai.backend.session-id"]))
kernel_session_map[kernel_id] = session_id
Expand Down
Loading