Skip to content
Closed
Show file tree
Hide file tree
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: 9 additions & 7 deletions tensorrt_llm/serve/disagg_coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,8 @@ async def _on_worker_event(self, worker_info: WorkerInfo, event_type: WatchEvent
# so the CLIENT always closes an idle connection first; see
# ``make_coordinator_session``. Mirrors ``openai_client``'s worker-facing pool.
COORDINATOR_KEEPALIVE_TIMEOUT_S = 1
# Per client session: excess calls queue in the pool instead of overflowing the accept backlog.
COORDINATOR_UDS_CONNECTION_LIMIT = 128

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

128 is close to aiohttp's default of 100, and the removed docstring blamed that default for hundreds of ms of /select latency at about 320 in-flight calls per worker (c1280/4). Measure steady-state /select latency at that load, or make the limit configurable.



def coordinator_base_url(remote_url: str) -> str:
Expand All @@ -694,12 +696,10 @@ def make_coordinator_session(remote_url: str) -> aiohttp.ClientSession:
when the fleet is co-located with the implicit coordinator. Callers create
the session lazily so it binds to the running event loop.

limit=0 (unlimited pool): each fleet worker has ~concurrency/num_workers
requests in flight (e.g. 320 at c1280/4), but aiohttp's default pool caps at
100 -- so most /select,/finish calls were BLOCKING on a free pooled
connection, which was the real ~hundreds-of-ms client.select latency (not the
~0.1ms handler, not the transport). Uncapping lets all concurrent calls hold
a connection. The coordinator is a trusted local socket, so no cap needed.
UDS calls beyond a session's connection limit queue in its connector, within

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A queued call waits under its own total timeout, not under the router's request timeout. That is 5 s for /finish (COORDINATOR_FINISH_TIMEOUT_S) and 3600 s for a pooled /select, so fix the docstring to say this.

the router's request timeout. This bounds each client's connection pressure;
aggregate fleet concurrency can still exceed the listener's accept backlog.
TCP retains its existing pool policy.

keepalive_timeout below the coordinator's server-side keep-alive: aiohttp
does not probe a pooled connection before reuse, so whenever the SERVER
Expand All @@ -711,7 +711,9 @@ def make_coordinator_session(remote_url: str) -> aiohttp.ClientSession:
sock_path = remote_url[len(COORDINATOR_UDS_SCHEME) :]
return aiohttp.ClientSession(
connector=aiohttp.UnixConnector(
path=sock_path, limit=0, keepalive_timeout=COORDINATOR_KEEPALIVE_TIMEOUT_S
path=sock_path,
limit=COORDINATOR_UDS_CONNECTION_LIMIT,
Comment thread
liji-nv marked this conversation as resolved.
Resolved

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

High: with pooled generation admission (PooledLoadBalancingRouter), this cap can deadlock seat release.

In CoordinatorDelegatingRouter, one session per role carries /select, /finish and /renew (router.py:2588-2594). A pooled /select long-polls until a seat frees (timeout POOLED_SELECT_TIMEOUT_S = 3600 s), and a seat is freed only by /finish (or the 6 h expiry). aiohttp's timeout=<float> is a total timeout that also covers waiting for a pooled connection, and waiters are served FIFO. So once a worker has >=128 generation requests waiting for seats:

  • all 128 connections are held by selects;
  • /finish (timeout min(request_timeout, 5)) times out in the connector queue, backs off, and re-queues behind newer selects;
  • no seat is freed.

With every worker saturated (e.g. c1280 / 4 workers / 256 seats -> ~256 waiters per worker), generation stalls fleet-wide. With the default 60 s KV timeout, waiters fail with 503 after ~57 s, but each freed connection goes to the next queued select rather than a finish, so it is a livelock; with a null KV timeout the stall lasts up to the 3600 s select timeout. A client disconnect doesn't help either: the cancel path in get_next_server (router.py:2699-2719) shields the select and waits for it, and the release /finish it enqueues is starved too.

Possible fixes: keep limit=0 when the router is pooled; send /finish//renew through a separate session/connector; or bound pooled /select with a semaphore below the connector limit. Making 128 configurable alone wouldn't fix it.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reproduced with the actual session factory: 128 blocked /select calls prevent /finish from reaching the server. Three base runs pass; three head runs time out. Please isolate control traffic from long-polling selects.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A pooled router's generation /select holds its connection until a seat frees, and only a /finish sent through this same session frees one. Once 128 selects are waiting, /finish and /renew queue behind them, and seat-waiting requests stall until their KV-transfer deadline fails them, or until POOLED_SELECT_TIMEOUT_S (3600 s) when no deadline is set. Keep limit=0 for pooled routers, or send /finish and /renew through a connector of their own.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even with a dedicated /finish connector, a higher-priority /select can sit in the frontend connector queue while the coordinator grants a seat to a lower-priority waiter. Could the pooled path keep the coordinator in charge of admission ordering and count frontend queue time against the remaining context KV-transfer budget?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With pooled generation (max_requests_per_server), /select waits for an available seat. If 128 selections are waiting, they occupy every connection in this session. /finish uses the same session, so completed requests cannot release their seats.

If all active workers reach this state, generation admission stalls until selections time out. Without a KV transfer timeout, this can take up to one hour.

Please give /finish independent connection capacity. Add a test that fills the selection pool and verifies that /finish still releases a seat. The current test uses an external event to release requests, so it misses this dependency.

keepalive_timeout=COORDINATOR_KEEPALIVE_TIMEOUT_S,
)
)
return aiohttp.ClientSession(
Expand Down
90 changes: 86 additions & 4 deletions tests/unittest/disaggregated/test_coordinator_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1067,16 +1067,20 @@ def test_coordinator_session_gives_up_idle_connections_before_the_server():

assert dc.COORDINATOR_KEEPALIVE_TIMEOUT_S < TIMEOUT_KEEP_ALIVE

for url, connector_name in (
("unix:/tmp/trtllm_disagg_coord_8333.sock", "UnixConnector"),
("http://coordinator:8332", "TCPConnector"),
for url, connector_name, limit in (
(
"unix:/tmp/trtllm_disagg_coord_8333.sock",
"UnixConnector",
dc.COORDINATOR_UDS_CONNECTION_LIMIT,
),
("http://coordinator:8332", "TCPConnector", 0),
):
with (
patch.object(dc.aiohttp, connector_name) as connector,
patch.object(dc.aiohttp, "ClientSession"),
):
dc.make_coordinator_session(url)
assert connector.call_args.kwargs["limit"] == 0
assert connector.call_args.kwargs["limit"] == limit
assert connector.call_args.kwargs["keepalive_timeout"] == dc.COORDINATOR_KEEPALIVE_TIMEOUT_S


Expand All @@ -1102,6 +1106,84 @@ def fake_open(path, *args, **kwargs):
assert coordinator_server._effective_uds_backlog() == expected


@pytest.mark.asyncio
async def test_coordinator_uds_sessions_queue_at_their_own_limits(tmp_path):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Medium: this covers the happy path (saturate, then release externally). Could you add, with a monkeypatched small limit (e.g. 2):

  1. Pooled starvation: selects that only return once a /finish arrives on the same session; assert the finish still gets through (the case from the comment on disagg_coordinator.py).
  2. A queued call that is cancelled, followed by limit successful calls (no slot leak).
  3. A queued post(timeout=0.2) that raises TimeoutError while the pool is full.

"""Independent sessions queue locally; their aggregate concurrency exceeds one pool's limit."""
from contextlib import AsyncExitStack

from aiohttp import web

from tensorrt_llm.serve.disagg_coordinator import (
COORDINATOR_UDS_CONNECTION_LIMIT,
make_coordinator_session,
)

# Sixteen sessions at their limits fill uvicorn's default accept backlog.
session_count = 16
Comment thread
liji-nv marked this conversation as resolved.
Resolved

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test holds about 4,100 descriptors open in one process, so on a host with a soft RLIMIT_NOFILE of 1024 it times out instead of skipping. Raise the soft limit with resource.setrlimit, or skip below about 4,200 as tests/unittest/grpc/openengine/test_frontend_lifecycle.py:76 does.

ready, release = asyncio.Event(), asyncio.Event()
limit = COORDINATOR_UDS_CONNECTION_LIMIT
live, peak = [0] * session_count, [0] * session_count
total_peak = 0

async def select(request):
nonlocal total_peak
session_id = int(request.match_info["session_id"])
live[session_id] += 1
peak[session_id] = max(peak[session_id], live[session_id])
total_peak = max(total_peak, sum(live))
if all(count == limit for count in live):
ready.set()
try:
await release.wait()
return web.Response(text=request.match_info["request_id"])
finally:
live[session_id] -= 1

app = web.Application()
app.router.add_post("/select/{session_id}/{request_id}", select)
runner = web.AppRunner(app)
await runner.setup()
socket_path = str(tmp_path / "coordinator.sock")
# Match the running uvicorn version's default, rather than assuming a
# particular kernel/library backlog. This test checks connector queuing,
# not that arbitrary fleet sizes fit the accept queue.
backlog = uvicorn.Config(app).backlog

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Medium: this sizes against uvicorn's default backlog (2048), but the production coordinator listener uses COORDINATOR_UDS_BACKLOG (16384, capped by somaxconn; coordinator_server.py:59, 101-107), which landed in #21997 after this PR's measurements. Could you re-measure the burst loss on current main to confirm the cap is still needed, and have the test reference _effective_uds_backlog() (or simply use a small patched limit)? As written, the test also needs ~4.1k fds and somaxconn >= 2048 on the CI host, and uvicorn.Config() reconfigures logging globally.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The production UDS listener uses COORDINATOR_UDS_BACKLOG, not uvicorn's default. Give this test a fixed backlog of its own and drop the uvicorn.Config(app).backlog assertion and the comment at line 1121.

assert session_count * limit <= backlog
await web.UnixSite(runner, socket_path, backlog=backlog).start()
try:
async with AsyncExitStack() as stack:
sessions = [
await stack.enter_async_context(make_coordinator_session("unix:" + socket_path))
for _ in range(session_count)
]

async def call(session_id, request_id):
async with sessions[session_id].post(
f"http://localhost/select/{session_id}/{request_id}"
) as response:
response.raise_for_status()
return int(await response.text())

requests_per_session = 2 * limit
calls = [
asyncio.create_task(call(session_id, index))
for session_id in range(session_count)
for index in range(requests_per_session)
]
try:
await asyncio.wait_for(ready.wait(), 15)
await asyncio.sleep(0.05)
assert live == [limit] * session_count
finally:
release.set()
replies = await asyncio.wait_for(asyncio.gather(*calls), 15)
assert replies == list(range(requests_per_session)) * session_count
assert peak == [limit] * session_count
assert total_peak == limit * session_count
finally:
await runner.cleanup()


@pytest.mark.asyncio
@pytest.mark.parametrize(
("keep_alive_kwargs", "expected_timeout"),
Expand Down