diff --git a/CHANGELOG.md b/CHANGELOG.md index 46428ca95..4d6e859ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,13 @@ The following emojis are used to highlight certain changes: ### Security +## [v0.27.3] + +### Added + +- `provider`: Added `LastRun` and `NextRun` stats to the Reprovider [#815](https://github.com/ipfs/boxo/pull/815) + + ## [v0.27.2] ### Fixed diff --git a/provider/reprovider.go b/provider/reprovider.go index 2959b64b8..4fdba4f51 100644 --- a/provider/reprovider.go +++ b/provider/reprovider.go @@ -58,10 +58,12 @@ type reprovider struct { noReprovideInFlight chan struct{} maxReprovideBatchSize uint + acceleratedDHTClient bool statLk sync.Mutex totalProvides, lastReprovideBatchSize uint64 avgProvideDuration, lastReprovideDuration time.Duration + lastRun time.Time throughputCallback ThroughputCallback // throughputProvideCurrentCount counts how many provides has been done since the last call to throughputCallback @@ -160,6 +162,13 @@ func Allowlist(allowlist verifcid.Allowlist) Option { } } +func AcceleratedDHTClient(v bool) Option { + return func(system *reprovider) error { + system.acceleratedDHTClient = v + return nil + } +} + func ReproviderInterval(duration time.Duration) Option { return func(system *reprovider) error { system.reprovideInterval = duration @@ -357,6 +366,9 @@ func (s *reprovider) run() { s.statLk.Lock() s.avgProvideDuration = (totalProvideTime + dur) / (time.Duration(s.totalProvides) + time.Duration(len(keys))) s.totalProvides += uint64(len(keys)) + if s.acceleratedDHTClient { + s.lastRun = time.Now() + } log.Debugf("finished providing of %d keys. It took %v with an average of %v per provide", len(keys), dur, recentAvgProvideDuration) @@ -539,6 +551,7 @@ func (s *reprovider) shouldReprovide() bool { type ReproviderStats struct { TotalProvides, LastReprovideBatchSize uint64 AvgProvideDuration, LastReprovideDuration time.Duration + LastRun, NextRun time.Time } // Stat returns various stats about this provider system @@ -550,6 +563,8 @@ func (s *reprovider) Stat() (ReproviderStats, error) { LastReprovideBatchSize: s.lastReprovideBatchSize, AvgProvideDuration: s.avgProvideDuration, LastReprovideDuration: s.lastReprovideDuration, + LastRun: s.lastRun, + NextRun: s.lastRun.Add(DefaultReproviderInterval), }, nil }