Skip to content

Commit

Permalink
cmd/dist: increase test parallelism starting with GOMAXPROCS=2 runtime
Browse files Browse the repository at this point in the history
Fixes golang#65164

Change-Id: Ia10952f50a3c2a7868e30dcdba333927947b3ac3
  • Loading branch information
qiulaidongfeng committed Feb 14, 2024
1 parent 69d6c7b commit cc5f615
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/cmd/dist/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1272,8 +1272,8 @@ func (t *tester) runPending(nextTest *distTest) {
worklist := t.worklist
t.worklist = nil
for _, w := range worklist {
w.start = make(chan bool)
w.end = make(chan struct{})
w.start = make(chan bool, runtime.NumCPU()*2)
w.end = make(chan struct{}, runtime.NumCPU()*2)
// w.cmd must be set up to write to w.out. We can't check that, but we
// can check for easy mistakes.
if w.cmd.Stdout == nil || w.cmd.Stdout == os.Stdout || w.cmd.Stderr == nil || w.cmd.Stderr == os.Stderr {
Expand Down Expand Up @@ -1303,6 +1303,21 @@ func (t *tester) runPending(nextTest *distTest) {
}(w)
}

// for runtime.NumCPU() > 4 , do not change maxbg.
// Because there is not enough CPU to parallel the testing of multiple packages.
if runtime.NumCPU() > 4 {
for _, w := range worklist {
// because GOMAXPROCS=2 runtime CPU usage is low,
// so increase maxbg to avoid slowing down execution with low CPU usage.
// This makes testing a single package slower,
// but testing multiple packages together faster.
if strings.Contains(w.dt.heading, "GOMAXPROCS=2 runtime") {
maxbg = runtime.NumCPU() * 2
break
}
}
}

started := 0
ended := 0
var last *distTest
Expand Down

0 comments on commit cc5f615

Please sign in to comment.