feat: add nearest DC detection with TCP race#763
feat: add nearest DC detection with TCP race#763r142f wants to merge 19 commits intoydb-platform:mainfrom
Conversation
1cced85 to
139dde2
Compare
There was a problem hiding this comment.
Pull request overview
This PR adds an opt-in “nearest datacenter” selection mechanism for endpoint discovery, using a TCP connection race to prefer endpoints in the lowest-latency location when DriverConfig(detect_local_dc=True) is enabled.
Changes:
- Add sync + async
nearest_dcmodules implementing TCP-race-based location detection. - Wire DC detection into sync and async discovery pools to mark endpoints in the detected location as preferred.
- Add
detect_local_dcflag toDriverConfigand introduce unit tests for both sync and async implementations.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| ydb/pool.py | Uses detected local DC (when enabled) to set endpoint preference during discovery. |
| ydb/nearest_dc.py | Implements synchronous TCP race DC detection helpers. |
| ydb/driver.py | Adds detect_local_dc configuration flag to DriverConfig. |
| ydb/aio/pool.py | Async discovery now prefers endpoints in the detected local DC. |
| ydb/aio/nearest_dc.py | Implements asynchronous TCP race DC detection helpers. |
| tests/test_nearest_dc.py | Adds unit tests for sync nearest DC detection behavior. |
| tests/aio/test_nearest_dc.py | Adds unit tests for async nearest DC detection behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
75c84c6 to
33826e7
Compare
|
Hi! Awesome PR! one little suggestion: can you move nearest_dc contents to _utilities modules? I don't think we need to add another file for this |
|
|
||
| if ssl_filtered_endpoints: | ||
| try: | ||
| detected_location = _utilities.detect_local_dc( |
There was a problem hiding this comment.
we don't have any cache here - the number of endpoints could be huge
🌋 SLO Test ResultsStatus: 🟢 2 workloads tested • All passed
Generated by ydb-slo-action |
Add automatic nearest datacenter detection for connection pooling
Pull request type
What is the current behavior?
The SDK uses round-robin load balancing across all discovered endpoints without considering network latency, which can lead to suboptimal performance in multi-datacenter deployments.
Fixes: #446
Fixes: #592
What is the new behavior?
Adds opt-in nearest datacenter detection (enabled via
DriverConfig(detect_local_dc=True)) that uses TCP connection racing to identify and prioritize the fastest-responding datacenter, reducing request latency in multi-DC deployments.Other information