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

Add randomization in sync retry batch peer selection #5822

Merged
merged 4 commits into from
Jul 9, 2024

Conversation

dapplion
Copy link
Collaborator

Issue Addressed

When retrying a batch, peers are prioritized by:

  1. They have some failures
  2. Count of active requets
  3. Break tie with NodeID value

While the prioritization is okay, breaking ties by NodeID is not fair and prioritizes peers that just happen to have a peer ID if a smaller value or those that have farmed peer IDs with smaller values.

Proposed Changes

Add a random u32 before sorting batch retry peers

@dapplion dapplion requested a review from AgeManning May 22, 2024 13:14
@jimmygchen jimmygchen added ready-for-review The code is ready for review Networking labels May 23, 2024
Copy link
Member

@jxs jxs left a comment

Choose a reason for hiding this comment

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

the rationale for the change makes sense to me! Left a comment wrt to the implementation only

*peer,
)
})
.collect::<Vec<_>>();
// Sort peers prioritizing unrelated peers with less active requests.
priorized_peers.sort_unstable();
priorized_peers.first().map(|&(_, _, peer)| peer)
priorized_peers.first().map(|&(_, _, _, peer)| peer)
Copy link
Member

Choose a reason for hiding this comment

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

not related with this PR, but do we need to iterate, collect, and then sort? To get the lowest peer by that Ord criteria we can just iterate once and get the lowest with :

let new_peer = self
            .network_globals
            .peers
            .read()
            .synced_peers()
            .map(|peer| {
                (
                    failed_peers.contains(peer),
                    self.active_requests.get(peer).map(|v| v.len()).unwrap_or(0),
                    rand::thread_rng().gen::<u32>(),
                    *peer,
                )
            })
            .min()
            .map(|(_, _, _, peer)| peer);

same applies to the other change on this PR

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Nice suggestion! Pushed

Copy link
Member

@jxs jxs left a comment

Choose a reason for hiding this comment

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

LGTM lion! Left one final suggestion which can just be applied

beacon_node/network/src/sync/backfill_sync/mod.rs Outdated Show resolved Hide resolved
beacon_node/network/src/sync/backfill_sync/mod.rs Outdated Show resolved Hide resolved
Co-authored-by: João Oliveira <hello@jxs.pt>
@jxs
Copy link
Member

jxs commented Jul 1, 2024

@Mergifyio queue

Copy link

mergify bot commented Jul 1, 2024

queue

🛑 The pull request has been removed from the queue default

The queue conditions cannot be satisfied due to failing checks.

You can take a look at Queue: Embarked in merge queue check runs for more details.

In case of a failure due to a flaky test, you should first retrigger the CI.
Then, re-embark the pull request into the merge queue by posting the comment
@mergifyio refresh on the pull request.

mergify bot added a commit that referenced this pull request Jul 1, 2024
@jxs
Copy link
Member

jxs commented Jul 4, 2024

@mergify refresh

Copy link

mergify bot commented Jul 4, 2024

refresh

✅ Pull request refreshed

@jxs
Copy link
Member

jxs commented Jul 8, 2024

@Mergifyio queue

Copy link

mergify bot commented Jul 8, 2024

queue

✅ The pull request has been merged automatically

The pull request has been merged automatically at 2e2ccec

mergify bot added a commit that referenced this pull request Jul 8, 2024
@mergify mergify bot merged commit 2e2ccec into sigp:unstable Jul 9, 2024
28 checks passed
@dapplion dapplion deleted the peer-prio branch July 10, 2024 08:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Networking ready-for-review The code is ready for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants