From 760d0220f4f21eabdf59ae0c0d0de65b9776f98b Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Sun, 30 Nov 2025 11:01:01 +0100 Subject: [PATCH] restorer: scale file cache with workers count --- internal/restorer/filerestorer.go | 10 ++++------ internal/restorer/fileswriter.go | 8 +++++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/internal/restorer/filerestorer.go b/internal/restorer/filerestorer.go index bb7e6de23..d197bcf5b 100644 --- a/internal/restorer/filerestorer.go +++ b/internal/restorer/filerestorer.go @@ -79,12 +79,10 @@ func newFileRestorer(dst string, workerCount := int(connections) return &fileRestorer{ - idx: idx, - blobsLoader: blobsLoader, - startWarmup: startWarmup, - // use a large number of buckets to minimize bucket contention in filesWriter - // buckets are relatively cheap, so we can afford to have a lot of them - filesWriter: newFilesWriter(1024, allowRecursiveDelete), + idx: idx, + blobsLoader: blobsLoader, + startWarmup: startWarmup, + filesWriter: newFilesWriter(workerCount, allowRecursiveDelete), zeroChunk: repository.ZeroChunk(), sparse: sparse, progress: progress, diff --git a/internal/restorer/fileswriter.go b/internal/restorer/fileswriter.go index e69b74544..2b60f7185 100644 --- a/internal/restorer/fileswriter.go +++ b/internal/restorer/fileswriter.go @@ -37,12 +37,14 @@ type partialFile struct { } func newFilesWriter(count int, allowRecursiveDelete bool) *filesWriter { - buckets := make([]filesWriterBucket, count) - for b := 0; b < count; b++ { + // use a large number of buckets to minimize bucket contention + // creating a new file can be slow, so make sure that files typically end up in different buckets. + buckets := make([]filesWriterBucket, 1024) + for b := 0; b < len(buckets); b++ { buckets[b].files = make(map[string]*partialFile) } - cache, err := simplelru.NewLRU[string, *partialFile](50, func(_ string, wr *partialFile) { + cache, err := simplelru.NewLRU[string, *partialFile](count+50, func(_ string, wr *partialFile) { // close the file only when it is not in use if wr.users == 0 { _ = wr.Close()