-
Notifications
You must be signed in to change notification settings - Fork 22
feat(client): round-robin outbound connections across source IPs #370
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -9,6 +9,7 @@ | |||||||||||||
|
|
||||||||||||||
| from unittest.mock import patch | ||||||||||||||
|
|
||||||||||||||
| import pytest | ||||||||||||||
| from inference_endpoint.endpoint_client import config as cfg | ||||||||||||||
| from inference_endpoint.endpoint_client.cpu_affinity import UnsupportedPlatformError | ||||||||||||||
|
|
||||||||||||||
|
|
@@ -43,3 +44,62 @@ def test_http_client_config_constructs_when_numa_unsupported(self): | |||||||||||||
| ): | ||||||||||||||
| c = cfg.HTTPClientConfig() | ||||||||||||||
| assert c.num_workers == 10 | ||||||||||||||
|
|
||||||||||||||
|
|
||||||||||||||
| class TestSourceIpsBudgetScaling: | ||||||||||||||
| """source_ips multiplies the ephemeral-port budget by the IP count.""" | ||||||||||||||
|
|
||||||||||||||
| # num_workers is pinned (>=1) so config resolution skips NUMA auto-probe. | ||||||||||||||
|
|
||||||||||||||
| def test_blank_source_ips_are_dropped(self): | ||||||||||||||
| c = cfg.HTTPClientConfig(source_ips=["127.0.0.1", " ", "", "127.0.0.2"]) | ||||||||||||||
| assert c.source_ips == ["127.0.0.1", "127.0.0.2"] | ||||||||||||||
|
Comment on lines
+54
to
+56
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. Update the test to verify that duplicate source IPs are also correctly deduplicated and cleaned.
Suggested change
|
||||||||||||||
|
|
||||||||||||||
| def test_auto_max_connections_scales_by_source_ip_count(self): | ||||||||||||||
| with ( | ||||||||||||||
| patch.object(cfg, "get_ephemeral_port_range", return_value=(32768, 60999)), | ||||||||||||||
| patch.object(cfg, "get_ephemeral_port_limit", return_value=10000), | ||||||||||||||
| ): | ||||||||||||||
| c = cfg.HTTPClientConfig( | ||||||||||||||
| endpoint_urls=["http://localhost:8000"], | ||||||||||||||
| num_workers=10, | ||||||||||||||
| source_ips=["1.1.1.1", "2.2.2.2", "3.3.3.3"], | ||||||||||||||
| ) | ||||||||||||||
| assert c.max_connections == 30000 # 10000 available x 3 source IPs | ||||||||||||||
|
|
||||||||||||||
| def test_auto_max_connections_unchanged_without_source_ips(self): | ||||||||||||||
| with ( | ||||||||||||||
| patch.object(cfg, "get_ephemeral_port_range", return_value=(32768, 60999)), | ||||||||||||||
| patch.object(cfg, "get_ephemeral_port_limit", return_value=10000), | ||||||||||||||
| ): | ||||||||||||||
| c = cfg.HTTPClientConfig( | ||||||||||||||
| endpoint_urls=["http://localhost:8000"], num_workers=10 | ||||||||||||||
| ) | ||||||||||||||
| assert c.max_connections == 10000 # single-IP budget, unchanged | ||||||||||||||
|
|
||||||||||||||
| def test_explicit_max_connections_within_scaled_budget_ok(self): | ||||||||||||||
| # 25000 exceeds the single-IP budget (10000) but fits 3 IPs (30000). | ||||||||||||||
| with ( | ||||||||||||||
| patch.object(cfg, "get_ephemeral_port_range", return_value=(32768, 60999)), | ||||||||||||||
| patch.object(cfg, "get_ephemeral_port_limit", return_value=10000), | ||||||||||||||
| ): | ||||||||||||||
| c = cfg.HTTPClientConfig( | ||||||||||||||
| endpoint_urls=["http://localhost:8000"], | ||||||||||||||
| num_workers=10, | ||||||||||||||
| max_connections=25000, | ||||||||||||||
| source_ips=["1.1.1.1", "2.2.2.2", "3.3.3.3"], | ||||||||||||||
| ) | ||||||||||||||
| assert c.max_connections == 25000 | ||||||||||||||
|
|
||||||||||||||
| def test_explicit_max_connections_exceeding_scaled_budget_raises(self): | ||||||||||||||
| with ( | ||||||||||||||
| patch.object(cfg, "get_ephemeral_port_range", return_value=(32768, 60999)), | ||||||||||||||
| patch.object(cfg, "get_ephemeral_port_limit", return_value=10000), | ||||||||||||||
| ): | ||||||||||||||
| with pytest.raises(RuntimeError, match="exceeds ephemeral port"): | ||||||||||||||
| cfg.HTTPClientConfig( | ||||||||||||||
| endpoint_urls=["http://localhost:8000"], | ||||||||||||||
| num_workers=10, | ||||||||||||||
| max_connections=40000, | ||||||||||||||
| source_ips=["1.1.1.1", "2.2.2.2", "3.3.3.3"], | ||||||||||||||
| ) | ||||||||||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
If duplicate IP addresses are provided in
--source-ips(e.g.,["127.0.0.1", "127.0.0.1"]), they are not filtered out. This will causelen(self.source_ips)to count duplicates, leading to an incorrect (overestimated) ephemeral port budget calculation in_resolve_defaults.Deduplicating the list while preserving order using
dict.fromkeysensures the budget is scaled accurately.