2
2
mirror of https://github.com/octoleo/restic.git synced 2024-12-22 10:58:55 +00:00

helper: Reduce number of parallel builds a bit

The go compiler is already parallelized. The high concurrency caused my
podman container to hit a resource limit.
This commit is contained in:
Michael Eischer 2022-08-20 12:10:48 +02:00
parent ed94678820
commit 7f0929e519

View File

@ -182,14 +182,19 @@ func buildForTarget(sourceDir, outputDir, goos, goarch string) (filename string)
func buildTargets(sourceDir, outputDir string, targets map[string][]string) { func buildTargets(sourceDir, outputDir string, targets map[string][]string) {
start := time.Now() start := time.Now()
msg("building with %d workers", runtime.NumCPU()) // the go compiler is already parallelized, thus reduce the concurrency a bit
workers := runtime.GOMAXPROCS(0) / 4
if workers < 1 {
workers = 1
}
msg("building with %d workers", workers)
type Job struct{ GOOS, GOARCH string } type Job struct{ GOOS, GOARCH string }
var wg errgroup.Group var wg errgroup.Group
ch := make(chan Job) ch := make(chan Job)
for i := 0; i < runtime.NumCPU(); i++ { for i := 0; i < workers; i++ {
wg.Go(func() error { wg.Go(func() error {
for job := range ch { for job := range ch {
start := time.Now() start := time.Now()