Repository navigation
[TRTLLM-16622][fix] DeepSeek-V4.1: bound the disaggregated coordinator's UDS connections per session #22353
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
[TRTLLM-16622][fix] DeepSeek-V4.1: bound the disaggregated coordinator's UDS connections per session #22353
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
||
|
|
||
| def coordinator_base_url(remote_url: str) -> str: | ||
|
|
@@ -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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| 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 | ||
|
|
@@ -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, | ||
|
liji-nv marked this conversation as resolved.
Resolved
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. High: with pooled generation admission ( In
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 Possible fixes: keep
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A pooled router's generation
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Even with a dedicated
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With pooled generation ( 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 |
||
| keepalive_timeout=COORDINATOR_KEEPALIVE_TIMEOUT_S, | ||
| ) | ||
| ) | ||
| return aiohttp.ClientSession( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
||
|
|
||
|
|
@@ -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): | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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):
|
||
| """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 | ||
|
liji-nv marked this conversation as resolved.
Resolved
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| 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 | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The production UDS listener uses |
||
| 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"), | ||
|
|
||
There was a problem hiding this comment.
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
/selectlatency at about 320 in-flight calls per worker (c1280/4). Measure steady-state/selectlatency at that load, or make the limit configurable.