feat(p2p): Implement peer speed weighting for segment downloads#520
Open
feat(p2p): Implement peer speed weighting for segment downloads#520
Conversation
This commit modifies P2P peer selection to prioritize faster peers based on their historical throughput instead of random selection. It introduces `p2pPeerSpeedAveragingWindowMs` and `p2pPeerSpeedBaselineBps` configurations, integrates a bandwidth calculator in the `Peer` class, and uses a weighted random selection algorithm when multiple peers have a segment.
…ogic to use base speed as minimum threshold
…d minimum speed constant for peer selection
…s window in peer throughput calculation
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
This PR optimizes the P2P hybrid loader by implementing a peer speed weighting mechanism. Previously, when multiple peers had a requested segment, the peer was selected purely randomly. This update prioritizes faster peers based on their historical throughput to improve segment download efficiency and overall swarm health.
Changes
BandwidthCalculatorinto thePeerclass, which calculates and caches thedownloadBandwidthto avoid excessive calculation overhead.Utils.getWeightedRandomItem) inloader.ts. Faster peers now have higher selection probabilities. New or untested peers are allocated a baseline throughput (or 10% of the max speed in the swarm) to ensure they continue to be organically benchmarked.