From 83744781180f3ebda255ec576d61761ff09873a9 Mon Sep 17 00:00:00 2001 From: Sergey Gorbunov Date: Mon, 27 Jan 2025 16:48:13 +0300 Subject: [PATCH 1/5] Add LastRun and NextRun stats. --- provider/reprovider.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/provider/reprovider.go b/provider/reprovider.go index 048a2067d..2dae9f497 100644 --- a/provider/reprovider.go +++ b/provider/reprovider.go @@ -62,6 +62,7 @@ type reprovider struct { 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 @@ -357,6 +358,7 @@ func (s *reprovider) run() { s.statLk.Lock() s.avgProvideDuration = time.Duration((totalProvideTime + dur) / (time.Duration(s.totalProvides) + time.Duration(len(keys)))) s.totalProvides += uint64(len(keys)) + 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 +541,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 +553,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 } From d1c84005bb114e9f98f9ed7f7311d77263a19c63 Mon Sep 17 00:00:00 2001 From: Sergey Gorbunov Date: Tue, 28 Jan 2025 14:30:56 +0300 Subject: [PATCH 2/5] Update the changelog. --- CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 46428ca95..a2264322b 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 From 540ba544d37b84c398307121fbaac8c85efee2d7 Mon Sep 17 00:00:00 2001 From: Guillaume Michel Date: Thu, 30 Jan 2025 11:25:25 +0100 Subject: [PATCH 3/5] changelog nits --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a2264322b..4d6e859ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,7 +29,7 @@ The following emojis are used to highlight certain changes: ### Added -- `provider` Added LastRun and NextRun stats to the Reprovider. [#815](https://github.com/ipfs/boxo/pull/815) +- `provider`: Added `LastRun` and `NextRun` stats to the Reprovider [#815](https://github.com/ipfs/boxo/pull/815) ## [v0.27.2] From 5bc192e098c3576b2a6855f27e85f54d9ebae923 Mon Sep 17 00:00:00 2001 From: Sergey Gorbunov Date: Thu, 30 Jan 2025 18:31:34 +0300 Subject: [PATCH 4/5] Stat LastRun and NextRun only if kubo is running with the Accelerated DHT --- provider/reprovider.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/provider/reprovider.go b/provider/reprovider.go index c5f356314..4fdba4f51 100644 --- a/provider/reprovider.go +++ b/provider/reprovider.go @@ -58,6 +58,7 @@ type reprovider struct { noReprovideInFlight chan struct{} maxReprovideBatchSize uint + acceleratedDHTClient bool statLk sync.Mutex totalProvides, lastReprovideBatchSize uint64 @@ -161,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 @@ -358,7 +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)) - s.lastRun = time.Now() + 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) From 4e2d874c1486999b827559d6bc8972e6e939aed8 Mon Sep 17 00:00:00 2001 From: guillaumemichel Date: Fri, 31 Jan 2025 11:45:09 +0100 Subject: [PATCH 5/5] removed NextRun from stats --- CHANGELOG.md | 2 +- provider/reprovider.go | 20 +++++--------------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d6e859ac..c9ebcc2c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,7 +29,7 @@ The following emojis are used to highlight certain changes: ### Added -- `provider`: Added `LastRun` and `NextRun` stats to the Reprovider [#815](https://github.com/ipfs/boxo/pull/815) +- `provider`: Added `ReprovideInterval` and `LastRun` stats to the Reprovider [#815](https://github.com/ipfs/boxo/pull/815) ## [v0.27.2] diff --git a/provider/reprovider.go b/provider/reprovider.go index 4fdba4f51..aeb5a27a5 100644 --- a/provider/reprovider.go +++ b/provider/reprovider.go @@ -58,7 +58,6 @@ type reprovider struct { noReprovideInFlight chan struct{} maxReprovideBatchSize uint - acceleratedDHTClient bool statLk sync.Mutex totalProvides, lastReprovideBatchSize uint64 @@ -162,13 +161,6 @@ 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 @@ -366,15 +358,13 @@ 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) if performedReprovide { s.lastReprovideBatchSize = uint64(len(keys)) s.lastReprovideDuration = dur + s.lastRun = time.Now() s.statLk.Unlock() @@ -549,9 +539,9 @@ func (s *reprovider) shouldReprovide() bool { } type ReproviderStats struct { - TotalProvides, LastReprovideBatchSize uint64 - AvgProvideDuration, LastReprovideDuration time.Duration - LastRun, NextRun time.Time + TotalProvides, LastReprovideBatchSize uint64 + ReprovideInterval, AvgProvideDuration, LastReprovideDuration time.Duration + LastRun time.Time } // Stat returns various stats about this provider system @@ -561,10 +551,10 @@ func (s *reprovider) Stat() (ReproviderStats, error) { return ReproviderStats{ TotalProvides: s.totalProvides, LastReprovideBatchSize: s.lastReprovideBatchSize, + ReprovideInterval: s.reprovideInterval, AvgProvideDuration: s.avgProvideDuration, LastReprovideDuration: s.lastReprovideDuration, LastRun: s.lastRun, - NextRun: s.lastRun.Add(DefaultReproviderInterval), }, nil }