Merge pull request #1172 from syncthing/random-scanintv
Add a random perturbation to the scan interval (fixes #1150)
This commit is contained in:
commit
9c6cb0f630
@ -21,6 +21,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sync"
|
"sync"
|
||||||
@ -225,10 +226,14 @@ loop:
|
|||||||
}
|
}
|
||||||
p.model.setState(p.folder, FolderIdle)
|
p.model.setState(p.folder, FolderIdle)
|
||||||
if p.scanIntv > 0 {
|
if p.scanIntv > 0 {
|
||||||
|
// Sleep a random time between 3/4 and 5/4 of the configured interval.
|
||||||
|
sleepNanos := (p.scanIntv.Nanoseconds()*3 + rand.Int63n(2*p.scanIntv.Nanoseconds())) / 4
|
||||||
|
intv := time.Duration(sleepNanos) * time.Nanosecond
|
||||||
|
|
||||||
if debug {
|
if debug {
|
||||||
l.Debugln(p, "next rescan in", p.scanIntv)
|
l.Debugln(p, "next rescan in", intv)
|
||||||
}
|
}
|
||||||
scanTimer.Reset(p.scanIntv)
|
scanTimer.Reset(intv)
|
||||||
}
|
}
|
||||||
if !initialScanCompleted {
|
if !initialScanCompleted {
|
||||||
l.Infoln("Completed initial scan (rw) of folder", p.folder)
|
l.Infoln("Completed initial scan (rw) of folder", p.folder)
|
||||||
|
|||||||
@ -17,6 +17,7 @@ package model
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math/rand"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -63,7 +64,9 @@ func (s *Scanner) Serve() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
timer.Reset(s.intv)
|
// Sleep a random time between 3/4 and 5/4 of the configured interval.
|
||||||
|
sleepNanos := (s.intv.Nanoseconds()*3 + rand.Int63n(2*s.intv.Nanoseconds())) / 4
|
||||||
|
timer.Reset(time.Duration(sleepNanos) * time.Nanosecond)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user