lib/weakhash, lib/model, cmd/syncthing: Decide if to use weakhash on startup (fixes #3938)

GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3949
This commit is contained in:
Audrius Butkevicius
2017-02-06 10:27:11 +00:00
parent 237893ead3
commit 67acef1794
12 changed files with 232 additions and 77 deletions

View File

@@ -113,7 +113,8 @@ func reportData(cfg configIntf, m modelIntf) map[string]interface{} {
var mem runtime.MemStats
runtime.ReadMemStats(&mem)
res["memoryUsageMiB"] = (mem.Sys - mem.HeapReleased) / 1024 / 1024
res["sha256Perf"] = cpuBench(5, 125*time.Millisecond)
res["sha256Perf"] = cpuBench(5, 125*time.Millisecond, false)
res["hashPerf"] = cpuBench(5, 125*time.Millisecond, true)
bytes, err := memorySize()
if err == nil {
@@ -286,10 +287,10 @@ func (s *usageReportingService) Stop() {
}
// cpuBench returns CPU performance as a measure of single threaded SHA-256 MiB/s
func cpuBench(iterations int, duration time.Duration) float64 {
func cpuBench(iterations int, duration time.Duration, useWeakHash bool) float64 {
var perf float64
for i := 0; i < iterations; i++ {
if v := cpuBenchOnce(duration); v > perf {
if v := cpuBenchOnce(duration, useWeakHash); v > perf {
perf = v
}
}
@@ -299,7 +300,7 @@ func cpuBench(iterations int, duration time.Duration) float64 {
var blocksResult []protocol.BlockInfo // so the result is not optimized away
func cpuBenchOnce(duration time.Duration) float64 {
func cpuBenchOnce(duration time.Duration, useWeakHash bool) float64 {
dataSize := 16 * protocol.BlockSize
bs := make([]byte, dataSize)
rand.Reader.Read(bs)
@@ -308,7 +309,7 @@ func cpuBenchOnce(duration time.Duration) float64 {
b := 0
for time.Since(t0) < duration {
r := bytes.NewReader(bs)
blocksResult, _ = scanner.Blocks(r, protocol.BlockSize, int64(dataSize), nil, true)
blocksResult, _ = scanner.Blocks(r, protocol.BlockSize, int64(dataSize), nil, useWeakHash)
b += dataSize
}
d := time.Since(t0)