From d1485d7c5fe48769b9a2cfe073ea976874b37f1d Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sun, 23 Aug 2020 17:46:35 -0700 Subject: [PATCH] Limit the number of threads to avoid pinning a host machine --- server/backup/archiver.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/server/backup/archiver.go b/server/backup/archiver.go index 9aa7603..5c2a8df 100644 --- a/server/backup/archiver.go +++ b/server/backup/archiver.go @@ -9,6 +9,7 @@ import ( "golang.org/x/sync/errgroup" "io" "os" + "runtime" "strings" "sync" ) @@ -28,7 +29,14 @@ func (a *Archive) Create(dst string, ctx context.Context) (os.FileInfo, error) { } defer f.Close() + maxCpu := runtime.NumCPU() / 2 + if maxCpu > 4 { + maxCpu = 4 + } + gzw, _ := gzip.NewWriterLevel(f, gzip.BestSpeed) + _ = gzw.SetConcurrency(1 << 20, maxCpu) + defer gzw.Flush() defer gzw.Close()