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

catchup: Dynamic parallel catchup #5802

Merged
merged 5 commits into from
Nov 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 deletions catchup/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
const catchupPeersForSync = 10
const blockQueryPeerLimit = 10

// uncapParallelDownloadRate is a simple threshold to detect whether or not the node is caught up.
// If a block is downloaded in less than this duration, it's assumed that the node is not caught up
// and allow the block downloader to start N=parallelBlocks concurrent fetches.
const uncapParallelDownloadRate = time.Second
winder marked this conversation as resolved.
Show resolved Hide resolved

// this should be at least the number of relays
const catchupRetryLimit = 500

Expand Down Expand Up @@ -85,6 +90,7 @@
auth BlockAuthenticator
parallelBlocks uint64
deadlineTimeout time.Duration
prevBlockFetchTime time.Time
blockValidationPool execpool.BacklogPool

// suspendForLedgerOps defines whether we've run into a state where the ledger is currently busy writing the
Expand Down Expand Up @@ -429,9 +435,16 @@

// TODO the following code does not handle the following case: seedLookback upgrades during fetch
func (s *Service) pipelinedFetch(seedLookback uint64) {
winder marked this conversation as resolved.
Show resolved Hide resolved
parallelRequests := s.parallelBlocks
if parallelRequests < seedLookback {
parallelRequests = seedLookback
maxParallelRequests := s.parallelBlocks
if maxParallelRequests < seedLookback {
maxParallelRequests = seedLookback

Check warning on line 440 in catchup/service.go

View check run for this annotation

Codecov / codecov/patch

catchup/service.go#L440

Added line #L440 was not covered by tests
}
minParallelRequests := seedLookback
winder marked this conversation as resolved.
Show resolved Hide resolved

// Start the limited requests at max(1, 'seedLookback')
limitedParallelRequests := uint64(1)
if limitedParallelRequests < seedLookback {
limitedParallelRequests = seedLookback
winder marked this conversation as resolved.
Show resolved Hide resolved
}

completed := make(map[basics.Round]chan bool)
Expand Down Expand Up @@ -461,7 +474,8 @@
nextRound := firstRound

for {
for nextRound < firstRound+basics.Round(parallelRequests) {
// launch N=parallelRequests block download go routines.
for nextRound < firstRound+basics.Round(limitedParallelRequests) {
if s.roundIsNotSupported(nextRound) {
// Break out of the loop to avoid fetching
// blocks that we don't support. If there
Expand All @@ -485,6 +499,7 @@
nextRound++
}

// wait for the first round to complete before starting the next download.
select {
case completedOK := <-completed[firstRound]:
delete(completed, firstRound)
Expand All @@ -495,6 +510,15 @@
return
}

fetchTime := time.Now()
fetchDur := fetchTime.Sub(s.prevBlockFetchTime)
winder marked this conversation as resolved.
Show resolved Hide resolved
s.prevBlockFetchTime = fetchTime
if fetchDur < uncapParallelDownloadRate {
limitedParallelRequests = maxParallelRequests
} else {
limitedParallelRequests = minParallelRequests
}

// if ledger is busy, pause for some time to let the fetchAndWrite goroutines to finish fetching in-flight blocks.
start := time.Now()
for (s.ledger.IsWritingCatchpointDataFile() || s.ledger.IsBehindCommittingDeltas()) && time.Since(start) < s.deadlineTimeout {
Expand Down