Skip to content

fix(client): scale connection budget by distinct endpoint count#371

Open
viraatc wants to merge 2 commits into
mainfrom
feat/scale-connection-budget-by-endpoints
Open

fix(client): scale connection budget by distinct endpoint count#371
viraatc wants to merge 2 commits into
mainfrom
feat/scale-connection-budget-by-endpoints

Conversation

@viraatc

@viraatc viraatc commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

Summary

The client's auto max_connections clamp 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 set max_connections to 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:

port_budget = available_ports * max(1, distinct_endpoints)
  • Single endpoint: unchanged.
  • Duplicate endpoints (same host:port, even different paths): don't inflate the budget — the 4-tuple ignores path.
  • Explicit --max-connections is validated against the scaled budget.

No new config or CLI — the multiplier comes from the endpoint_urls you already specify.

Validation

  • 5 unit tests: scaling by distinct endpoints, duplicates don't inflate, single-endpoint unchanged, explicit-budget within/exceeding.
  • OS-level, through the real 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):

destination (server port) connections before EADDRNOTAVAIL
:50001 28,227
:50002 28,228
:50003 28,228
total 84,683 = 3.00× the single-destination range
  • Source-port overlap across destinations: 28,227 — essentially every ephemeral port is reused across all 3 endpoints, directly confirming the 4-tuple reuse this PR relies on.
  • Idle pool memory: 13 bytes/connection (1.1 MB for all 84,683 sockets) — a scaled idle pool is effectively free; resident memory tracks in-flight data, not pool size.
  • fd ceiling: the GB200 compute node's RLIMIT_NOFILE hard 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

@viraatc viraatc requested a review from a team June 23, 2026 02:21
@github-actions

Copy link
Copy Markdown

MLCommons CLA bot All contributors have signed the MLCommons CLA ✍️ ✅

@gemini-code-assist gemini-code-assist Bot left a comment

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.

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.

Comment thread src/inference_endpoint/endpoint_client/config.py
viraatc and others added 2 commits June 24, 2026 00:38
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>
@viraatc viraatc force-pushed the feat/scale-connection-budget-by-endpoints branch from 95bb592 to f0ec348 Compare June 24, 2026 07:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants