Skip to content

Commit

Permalink
Merge pull request #57 from SkynetLabs/ivo/no_sleep
Browse files Browse the repository at this point in the history
Remove sleep between pins.
  • Loading branch information
Christopher Schinnerl authored Aug 25, 2022
2 parents af1e2c8 + eededa9 commit 847b832
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 24 deletions.
37 changes: 14 additions & 23 deletions workers/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,6 @@ var (
// servers, ordered by how much data they are pinning, below which a server
// will pin underpinned skylinks.
PinningRangeThresholdPercent = 0.30
// SleepBetweenPins defines how long we'll sleep between pinning files.
// We want to add this sleep in order to prevent a single server from
// grabbing all underpinned files and overloading itself. We also want to
// allow for some time for the newly pinned files to reach full redundancy
// before we pin more files.
SleepBetweenPins = build.Select(
build.Var{
Standard: 10 * time.Second,
Dev: time.Second,
Testing: time.Millisecond,
}).(time.Duration)
// SleepBetweenHealthChecks defines the wait time between calls to skyd to
// check the current health of a given file.
SleepBetweenHealthChecks = build.Select(
Expand All @@ -79,14 +68,20 @@ var (
Testing: time.Millisecond,
}).(time.Duration)

// minDeadline defines the minimum time we're going to wait for a skylink to
// reach full health before timing out.
minDeadline = build.Select(build.Var{
Standard: 30 * time.Second,
Dev: time.Second,
Testing: time.Millisecond,
}).(time.Duration)
// printPinningStatisticsPeriod defines how often we print intermediate
// statistics while pinning underpinned files.
printPinningStatisticsPeriod = build.Select(build.Var{
Standard: 10 * time.Minute,
Dev: 10 * time.Second,
Testing: 500 * time.Millisecond,
}).(time.Duration)

// sleepBetweenScans defines how often we'll scan the DB for underpinned
// skylinks.
// Needs to be at least twice as long as conf.SleepBetweenChecksForScan.
Expand Down Expand Up @@ -399,15 +394,6 @@ func (s *Scanner) managedPinUnderpinnedSkylinks() {
s.staticWaitUntilHealthy(skylink, sp)
continue
}
// In case of error we still want to sleep for a moment in order to
// avoid a tight(ish) loop of errors when we either fail to pin or
// fail to mark as pinned. Note that this only happens when we want
// to continue scanning, otherwise we would have exited right after
// managedFindAndPinOneUnderpinnedSkylink.
stopped := s.staticSleepForOrUntilStopped(SleepBetweenPins)
if stopped {
return
}
}
}

Expand Down Expand Up @@ -522,7 +508,8 @@ func (s *Scanner) staticEstimateTimeToFull(skylink skymodules.Skylink) time.Dura
if err != nil {
err = errors.AddContext(err, "failed to get metadata for skylink")
s.staticLogger.Error(err)
return SleepBetweenPins
// No metadata. Return some ballpark value that makes sense.
return SleepBetweenHealthChecks
}
chunkSize := 10 * modules.SectorSizeStandard
numChunks := meta.Length / chunkSize
Expand Down Expand Up @@ -657,5 +644,9 @@ func (s *Scanner) staticSleepForOrUntilStopped(dur time.Duration) bool {
// healthy before giving up. It's twice the expected time, as returned by
// staticEstimateTimeToFull.
func (s *Scanner) staticDeadline(skylink skymodules.Skylink) *time.Timer {
return time.NewTimer(2 * s.staticEstimateTimeToFull(skylink))
deadline := 2 * s.staticEstimateTimeToFull(skylink)
if deadline < minDeadline {
deadline = minDeadline
}
return time.NewTimer(deadline)
}
2 changes: 1 addition & 1 deletion workers/scanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ func testEstimateTimeToFull(t *testing.T, db *database.DB, cfg conf.Config, skyd
}{
"error": {
err: errors.New("error while fetching metadata"),
expTime: SleepBetweenPins, // 1ms
expTime: SleepBetweenHealthChecks, // 1ms
},
"zero": {
size: 0, // defaults to one chunk
Expand Down

0 comments on commit 847b832

Please sign in to comment.