Skip to content
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

Improve mirror selection logic in Closest with full-server fallback #22

Merged
merged 3 commits into from
Feb 22, 2025

Conversation

SuperKali
Copy link
Member

@SuperKali SuperKali commented Feb 19, 2025

This PR enhances the Closest function used for mirror selection by ensuring that all configured servers are considered, even when the initial filtering (based on availability, protocol, and rule checks) is too restrictive. It introduces a fallback mechanism, and more robust local mirror selection logic.

Fixes: Problems detecting nearest servers #15

Changes

  • Fallback Mechanism:

    • If the filtered list of valid servers (i.e., servers that are available, support the required protocol, and pass rule checks) contains fewer than two mirrors, the function now falls back to using the full server list.
    • This ensures that all configured mirrors are considered during mirror selection.
  • Local Mirror Selection:

    • After obtaining valid servers, the function filters for local servers (mirrors with the same country code as the client).
    • If at least one local mirror is found:
      • The distances are computed for each local mirror.
      • If the nearest local mirror is within a defined threshold (200 km), it is selected deterministically.
      • Otherwise, a weighted random selection is used among the local servers.
    • If no local mirrors are found, a weighted selection is performed among all valid servers.
  • Optional Rule Filtering:

    • The current filtering of valid servers includes checks for availability, protocol support, and custom rules.
    • For debugging purposes, the rule filtering can be temporarily disabled to ensure all mirrors are taken into account.

Impact

  • For Clients:
    Clients will now be more reliably directed to a local mirror when available, improving latency and download speed.

Please review the changes and let me know if further adjustments are needed.

@SuperKali SuperKali changed the title Improve mirror selection logic in Closest with full-server fallback and enhanced logging Improve mirror selection logic in Closest with full-server fallback Feb 20, 2025
@SuperKali
Copy link
Member Author

Hi @efectn,

I don't know if you've had a chance to look at my PR, let me know what you think.

Thank you.

…cache

    - Introduce SameCityThreshold in the Config struct
    - Replace the local constant sameCityThreshold with the configurable value
    - Store a single ComputedDistance in the cache instead of []randutil.Choice
@SuperKali SuperKali requested a review from efectn February 21, 2025 20:14
@efectn efectn merged commit d5b932a into armbian:master Feb 22, 2025
2 checks passed
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