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

feat: Better self-service commands for DHT providing #815

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions provider/reprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand All @@ -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
}

Expand Down