mirror of
https://github.com/rclone/rclone.git
synced 2024-11-22 16:34:30 +01:00
fs/accounting: fix moving average speed for file stats
Before this change the moving average for the individual file stats would start at 0 and only converge to the correct value over 15-30 seconds. This change starts the weighting period as 1 and moves it up once per sample which gets the average to a better value instantly.
This commit is contained in:
parent
66fe4a2523
commit
de6ec8056f
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user