fix(client): scale connection budget by distinct endpoint count#371
fix(client): scale connection budget by distinct endpoint count#371viraatc wants to merge 2 commits into
Conversation
|
MLCommons CLA bot All contributors have signed the MLCommons CLA ✍️ ✅ |
There was a problem hiding this comment.
Code Review
This pull request scales the maximum connections budget based on the number of distinct endpoints configured, preventing unnecessary concurrency throttling when multiple endpoints are used. It also introduces comprehensive unit tests to verify this scaling behavior. The review feedback identifies potential edge cases in the endpoint parsing logic, specifically regarding missing URL schemes and default ports (e.g., HTTP vs. HTTPS), which could lead to incorrect budget calculations, and suggests a more robust normalization approach.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
The ephemeral-port limit is per (source IP, destination) pair: the TCP 4-tuple (src_ip, src_port, dst_ip, dst_port) only needs to be unique, so the kernel reuses local ports across distinct destinations and each endpoint gets its own ~ephemeral-range budget. The auto max_connections clamp ignored this -- it capped the pool at a single pair's budget (available_ports), so configuring N frontends throttled total concurrency to one endpoint's worth, killing throughput for no reason even though workers are already round-robined across endpoints. Scale the clamp by the number of distinct (host, port) endpoints: port_budget = available_ports * max(1, distinct_endpoints) Single-endpoint behavior is unchanged; duplicate endpoints don't inflate it. Verified: 5 unit tests (scaling, duplicates, single-endpoint, explicit-budget validation); plus an OS-level check through the real ConnectionPool showing 1 endpoint sustains 999 concurrent connections while 5 endpoints sustain 4975 (995 each -- independent per-pair budgets), confirming the limit is per source-destination pair. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Address review feedback on the distinct-endpoint count that drives the ephemeral-port budget. The previous `(urlparse(u).hostname, urlparse(u).port)` key collapsed bare `host:port` inputs to `(None, None)` (urlparse treats the host as the scheme) and dropped the http/https distinction when ports were implicit. `_endpoint_destination` now prefixes a scheme when none is present and resolves the scheme default port (443 for https, else 80), so schemeless endpoints count distinctly and http/https to the same host stay separate. Also bump the transitive msgpack pin 1.1.2 -> 1.2.1 in uv.lock to clear GHSA-6v7p-g79w-8964 flagged by the pip-audit CI job. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
95bb592 to
f0ec348
Compare
Summary
The client's auto
max_connectionsclamp needlessly throttles throughput when multiple endpoints are configured.The ephemeral-port limit is per (source IP, destination) pair — the TCP 4-tuple
(src_ip, src_port, dst_ip, dst_port)only needs to be unique, so the kernel reuses local ports across distinct destinations and each endpoint gets its own ~ephemeral-range budget. But the auto clamp setmax_connectionsto a single pair's budget (available_ports), so listing N frontends capped total concurrency at one endpoint's worth — even though workers are already round-robined across endpoints (worker.py).Change
Scale the clamp by the number of distinct
(host, port)endpoints:host:port, even different paths): don't inflate the budget — the 4-tuple ignores path.--max-connectionsis validated against the scaled budget.No new config or CLI — the multiplier comes from the
endpoint_urlsyou already specify.Validation
ConnectionPool(one pool per destination, ephemeral range shrunk to 1000 ports in a netns): 1 endpoint → 999 simultaneous connections; 5 endpoints → 4975 (995 each — independent per-pair budgets), confirming the port limit is per source-destination pair and each endpoint contributes its own budget.Real-hardware verification (GB200, lyris, 2-node cross-node)
Exhausted the full ephemeral range (32768–60999 = 28,232 ports/destination) from a client node to 3 distinct destination ports on a separate server node, via the tool's real connect path (
create_connection, no source bind → autobind-at-connect):EADDRNOTAVAILRLIMIT_NOFILEhard cap is 131,072, so beyond ~4 endpoints the fd limit (not ephemeral ports) becomes the binding constraint — relevant when sizing very large--max-connections.🤖 Generated with Claude Code