Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

fs/accounting: fix moving average speed for file stats

Nick Craig-Woodde6ec8056fc1
diff --git a/fs/accounting/accounting.go b/fs/accounting/accounting.go
index a3746f5e9..398588d72 100644
--- a/fs/accounting/accounting.go
+++ b/fs/accounting/accounting.go
@@ -129,6 +129,7 @@ func (acc *Account) UpdateReader(in io.ReadCloser) {
// averageLoop calculates averages for the stats in the background
func (acc *Account) averageLoop() {
tick := time.NewTicker(time.Second)
+ var period float64
defer tick.Stop()
for {
select {
@@ -137,7 +138,11 @@ func (acc *Account) averageLoop() {
// Add average of last second.
elapsed := now.Sub(acc.lpTime).Seconds()
avg := float64(acc.lpBytes) / elapsed
- acc.avg = (avg + (averagePeriod-1)*acc.avg) / averagePeriod
+ // Soft start the moving average
+ if period < averagePeriod {
+ period++
+ }
+ acc.avg = (avg + (period-1)*acc.avg) / period
acc.lpBytes = 0
acc.lpTime = now
// Unlock stats