From 0ddf684376ef751a6c419a5bfcfe6d9cb2e4f66b Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Thu, 29 Oct 2020 13:54:39 +0000 Subject: [PATCH] marks pull request creation time only once per peer (#13113) (#13252) 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. (cherry picked from commit 4bfda3e766765b3bf30a68a694a88b4db922da10) Co-authored-by: behzad nouri --- 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 06eca4af18..1291a68f95 100644 --- a/core/src/cluster_info.rs +++ b/core/src/cluster_info.rs @@ -1469,11 +1469,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()