Limit the number of threads to avoid pinning a host machine

This commit is contained in:
Dane Everitt 2020-08-23 17:46:35 -07:00
parent 08bcb31b9e
commit d1485d7c5f
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53

View File

@ -9,6 +9,7 @@ import (
"golang.org/x/sync/errgroup" "golang.org/x/sync/errgroup"
"io" "io"
"os" "os"
"runtime"
"strings" "strings"
"sync" "sync"
) )
@ -28,7 +29,14 @@ func (a *Archive) Create(dst string, ctx context.Context) (os.FileInfo, error) {
} }
defer f.Close() defer f.Close()
maxCpu := runtime.NumCPU() / 2
if maxCpu > 4 {
maxCpu = 4
}
gzw, _ := gzip.NewWriterLevel(f, gzip.BestSpeed) gzw, _ := gzip.NewWriterLevel(f, gzip.BestSpeed)
_ = gzw.SetConcurrency(1 << 20, maxCpu)
defer gzw.Flush() defer gzw.Flush()
defer gzw.Close() defer gzw.Close()