Improve performance for syncing many small files quickly
Without this, as soon as we'd touched 1000 files in the last minute (which can happen), we got stuck doing cache cleaning all the time, burning a lot of CPU time.
This commit is contained in:
@@ -808,6 +808,20 @@ func (m *Model) Request(deviceID protocol.DeviceID, folder, name string, offset
|
||||
delete(m.reqValidationCache, name)
|
||||
}
|
||||
}
|
||||
|
||||
if len(m.reqValidationCache) > reqValidationCacheSize*9/10 {
|
||||
// The first clean didn't help much, we're still over 90%
|
||||
// full; we may have synced a lot of files lately. Prune the
|
||||
// cache more aggressively by removing every other item so we
|
||||
// don't get stuck doing useless cache cleaning.
|
||||
i := 0
|
||||
for name := range m.reqValidationCache {
|
||||
if i%2 == 0 {
|
||||
delete(m.reqValidationCache, name)
|
||||
}
|
||||
i++
|
||||
}
|
||||
}
|
||||
}
|
||||
m.rvmut.Unlock()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user