From 4bfda3e766765b3bf30a68a694a88b4db922da10 Mon Sep 17 00:00:00 2001 From: behzad nouri Date: Mon, 26 Oct 2020 13:11:31 -0400 Subject: [PATCH] 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. --- core/src/cluster_info.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/core/src/cluster_info.rs b/core/src/cluster_info.rs index 0c83fb7a2f..7b630a3747 100644 --- a/core/src/cluster_info.rs +++ b/core/src/cluster_info.rs @@ -1541,11 +1541,19 @@ impl ClusterInfo { self.stats .new_pull_requests_count .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 = 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 .into_iter() - .map(|(peer, filter, gossip, self_info)| { - self.time_gossip_write_lock("mark_pull", &self.stats.mark_pull_request) - .mark_pull_request_creation_time(&peer, now); + .map(|(_, filter, gossip, self_info)| { (gossip, Protocol::PullRequest(filter, self_info)) }) .collect()