From 491452a19dab4f9593ae127147dbe242537d81cf Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Mon, 20 Jul 2015 15:29:05 +0200 Subject: [PATCH] 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. --- internal/model/model.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/internal/model/model.go b/internal/model/model.go index 96dd68a72..89e04874f 100644 --- a/internal/model/model.go +++ b/internal/model/model.go @@ -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() }