Skip to content

TEL-1393: rank discovered regions near the preferred region - #1099

Open
hechen-eng wants to merge 2 commits into
mainfrom
discovery-near-region
Open

hechen-eng wants to merge 2 commits into
mainfrom
discovery-near-region

Conversation

@hechen-eng

Copy link
Copy Markdown
Contributor

Problem

WithPreferredRegion tries the caller's region before the regions from region discovery. Discovery ranks the regions by the GeoIP location of the client and returns only the closest ones that the project can use. That causes two problems:

  • The preferred region is tried even when the project cannot use it, for example when the project is pinned to other regions. The server refuses the join, and the SDK waits 100 ms before it tries the next region, so every such join is slower.
  • When GeoIP places the client far from its real region, the discovered regions after the preferred one are ranked from the wrong location.

Change

  • Region discovery sends the preferred region as near (/settings/regions?near=<region>). A server that supports it ranks the regions by distance from that region, and still lists only the regions the project can use. The region list is cached per near value.
  • If discovery returns regions and the preferred region is not one of them, the project cannot use it, so the SDK skips it and starts with the first discovered region. A debug log records the skip. If discovery fails or returns no regions, the SDK keeps the preferred region, as before.
  • The WithPreferredRegion doc describes this. A server without near support ignores the parameter and ranks by GeoIP, so its list can leave out a preferred region that the project can use. This change should be released after LiveKit Cloud supports near.

Region discovery sends the preferred region as near, so the server ranks the regions by distance from it. If the result does not include the preferred region, the project cannot use it, and the SDK skips it instead of trying a region that refuses the join.
devin-ai-integration[bot]

This comment was marked as resolved.

Joins with WithPreferredRegion read a separate region list for that region, so PrepareConnection warmed a list that they never read. PrepareConnection now takes the same ConnectOptions as the join.

@ChelseaBradbury ChelseaBradbury left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks reasonable to me 👍

Comment thread connection_manager.go Resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants