marks pull request creation time only once per peer (#13113)

mark_pull_request_creation time requires an exclusive lock on gossip:
https://github.com/solana-labs/solana/blob/16944e218/core/src/cluster_info.rs#L1547-L1548
Current code is redundantly marking each peer once for each request.
There are at most only 2 unique peers, whereas there are hundreds of
requests per each. So the lock is acquired hundreds of time longer than
necessary.
This commit is contained in:
behzad nouri 2020-10-26 13:11:31 -04:00 committed by GitHub
parent 439c06b460
commit 4bfda3e766
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 3 deletions

View File

@ -1541,11 +1541,19 @@ impl ClusterInfo {
self.stats self.stats
.new_pull_requests_count .new_pull_requests_count
.add_relaxed(pulls.len() as u64); .add_relaxed(pulls.len() as u64);
// There are at most 2 unique peers here: The randomly
// selected pull peer, and possibly also the entrypoint.
let peers: Vec<Pubkey> = pulls.iter().map(|(peer, _, _, _)| *peer).dedup().collect();
{
let mut gossip =
self.time_gossip_write_lock("mark_pull", &self.stats.mark_pull_request);
for peer in peers {
gossip.mark_pull_request_creation_time(&peer, now);
}
}
pulls pulls
.into_iter() .into_iter()
.map(|(peer, filter, gossip, self_info)| { .map(|(_, filter, gossip, self_info)| {
self.time_gossip_write_lock("mark_pull", &self.stats.mark_pull_request)
.mark_pull_request_creation_time(&peer, now);
(gossip, Protocol::PullRequest(filter, self_info)) (gossip, Protocol::PullRequest(filter, self_info))
}) })
.collect() .collect()