Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/compile: unable to fully utilize CPU after upgrading from Go 1.20 to 1.21 #63115

Closed
necheffa opened this issue Sep 20, 2023 · 3 comments
Closed
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Performance WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@necheffa
Copy link

What version of Go are you using (go version)?

$ go version
go version go1.21.1 linux/amd64

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

Debian 12.1 with an i7-1165g7.

go env Output
$ go env
GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/alex/.cache/go-build'
GOENV='/home/alex/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/alex/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/alex/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/opt/golang/go-1.21.1'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/opt/golang/go-1.21.1/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.21.1'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/home/alex/repaste_mini/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build2302350423=/tmp/go-build -gno-record-gcc-switches'

What did you do?

I compiled and executed the snippet of code below.

package main

import (
	"math"
	"math/rand"
	"runtime"
	"time"
)

const (
	timeLimit   = 1  // timeout in minutes
	timeSegment = 10 // sample rate in seconds
)

func Repaste(upTo int, done chan any) {
	for i := 0; i < upTo; i++ {
		select {
		case <-done:
			break
		default:
		}
		_ = math.Sqrt(rand.Float64())
	}
}

func main() {
	lim := runtime.NumCPU()
	done := make(chan any, lim)
	for i := 0; i < lim; i++ {
		go Repaste(math.MaxInt, done)
	}

	runTime := timeLimit * 60 // convert to seconds
	for i := 0; i < runTime; i += timeSegment {
		time.Sleep(timeSegment * time.Second)
	}

	for i := 0; i < lim; i++ {
		done <- i
	}

}

What did you expect to see?

I expected to see all 4 cores / 8 threads hit 4.1GHz during turbo boost.
NOTE: I am able to get this all-core clock speed with the exact same code snippet but built with Go 1.20.8 on the same machine, so I know it isn't a hardware issue like hitting thermal/power limits.

What did you see instead?

All cores / threads were at 100% utilization but only peaked at 3.6GHz.

It is also worth mentioning that I have tried other variations of "load" besides math.Sqrt(), such as just primitive arithmetic expressions, so this would not reflect a regression in the math package, the issue lies elsewhere.

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Sep 20, 2023
@necheffa
Copy link
Author

Removing channels entirely and letting the goroutines spin for a period of time before mashing Ctrl+C seems to allow full CPU utilization when building with Go 1.21.1, so it would seem to me that the perf regression likely lies somewhere in the implementation of channels.

@thanm thanm added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Sep 25, 2023
@mknyszek mknyszek added this to the Backlog milestone Oct 4, 2023
@mknyszek mknyszek added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Oct 4, 2023
@mdempsky
Copy link
Member

mdempsky commented Oct 4, 2023

I expected to see all 4 cores / 8 threads hit 4.1GHz during turbo boost.

All cores / threads were at 100% utilization but only peaked at 3.6GHz.

Are you able to quantify the impact of this further? E.g., do you have some benchmarks that show latency or throughput worsening?

The Go compiler and runtime don't manage CPU frequency. I also don't think we care about CPU frequency in isolation, unless it's affecting some other performance benchmarks (e.g., latency or throughput).

@gopherbot
Copy link

Timed out in state WaitingForInfo. Closing.

(I am just a bot, though. Please speak up if this is a mistake or you have the requested information.)

@gopherbot gopherbot closed this as not planned Won't fix, can't repro, duplicate, stale Nov 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Performance WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

6 participants