Skip to content

Commit

Permalink
try to reduce inflight_blocks write block hold duration
Browse files Browse the repository at this point in the history
  • Loading branch information
eval-exec committed Jul 24, 2023
1 parent b6cf8b4 commit 82a9434
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions sync/src/synchronizer/block_fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,11 @@ impl<'a> BlockFetcher<'a> {
}

let state = self.synchronizer.shared().state();
let mut inflight = state.write_inflight_blocks();
let mut start = last_common.number() + 1;
let mut end = min(best_known.number(), start + BLOCK_DOWNLOAD_WINDOW);
let n_fetch = min(
end.saturating_sub(start) as usize + 1,
inflight.peer_can_fetch_count(self.peer),
state.read_inflight_blocks().peer_can_fetch_count(self.peer),
);
let mut fetch = Vec::with_capacity(n_fetch);
let now = unix_time_as_millis();
Expand Down Expand Up @@ -184,12 +183,18 @@ impl<'a> BlockFetcher<'a> {
// Do not download repeatedly
} else if (matches!(self.ibd, IBDState::In)
|| state.compare_with_pending_compact(&hash, now))
&& inflight.insert(self.peer, (header.number(), hash).into())
&& state
.write_inflight_blocks()
.insert(self.peer, (header.number(), hash).into())
{
fetch.push(header)
}

status = self.active_chain.get_block_status(&parent_hash);
status = self
.synchronizer
.shared()
.shared()
.get_block_status(&parent_hash);
header = self
.synchronizer
.shared
Expand All @@ -209,7 +214,7 @@ impl<'a> BlockFetcher<'a> {
header.number().saturating_sub(CHECK_POINT_WINDOW) > unverified_tip
});
if should_mark {
inflight.mark_slow_block(tip);
state.write_inflight_blocks().mark_slow_block(tip);
}

if fetch.is_empty() {
Expand All @@ -221,19 +226,19 @@ impl<'a> BlockFetcher<'a> {
best_known.number(),
tip,
unverified_tip,
inflight.total_inflight_count(),
state.read_inflight_blocks().total_inflight_count(),
trace_timecost_now.elapsed().as_millis(),
);
trace!(
"[block fetch empty] peer-{}, inflight_state = {:?}",
self.peer,
*inflight
*state.read_inflight_blocks()
);
} else {
let fetch_head = fetch.first().map_or(0_u64.into(), |v| v.number());
let fetch_last = fetch.last().map_or(0_u64.into(), |v| v.number());
let inflight_peer_count = inflight.peer_inflight_count(self.peer);
let inflight_total_count = inflight.total_inflight_count();
let inflight_peer_count = state.read_inflight_blocks().peer_inflight_count(self.peer);
let inflight_total_count = state.read_inflight_blocks().total_inflight_count();
debug!(
"request peer-{} for batch blocks: [{}-{}], batch len:{}, [tip/unverified_tip]: [{}/{}], [peer/total inflight count]: [{} / {}], timecost: {}ms, blocks: {}",
self.peer,
Expand Down

0 comments on commit 82a9434

Please sign in to comment.