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

runtime: with -test.blockprofile program run even faster. #57319

Closed
zdyj3170101136 opened this issue Dec 15, 2022 · 3 comments
Closed

runtime: with -test.blockprofile program run even faster. #57319

zdyj3170101136 opened this issue Dec 15, 2022 · 3 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@zdyj3170101136
Copy link

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

$ go version
go version go1.19.3 linux/amd64

Does this issue reproduce with the latest release?

yes

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/usr/local/go/pkg/mod/"
GONOPROXY=""
GONOSUMDB="gopkg.mihoyo.com"
GOOS="linux"
GOPATH="/root/go"
GOPRIVATE=""
GOPROXY="https://goproxy.cn,direct"
GOROOT="/root/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/root/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.19.3"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/root/profilerbench/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build799047141=/tmp/go-build -gno-record-gcc-switches"GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/usr/local/go/pkg/mod/"
GONOPROXY=""
GONOSUMDB="gopkg.mihoyo.com"
GOOS="linux"
GOPATH="/root/go"
GOPRIVATE=""
GOPROXY="https://goproxy.cn,direct"
GOROOT="/root/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/root/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.19.3"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/root/profilerbench/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build799047141=/tmp/go-build -gno-record-gcc-switches"

What did you do?

run benchmark test of src/runtime/chan_test.go.
one with blockprofile, another not.

/root/go/bin/go test -run=^$ -bench=BenchmarkChanProdConsWork0$ -benchtime=10000000x
goos: linux
goarch: amd64
pkg: github.com/zdyj3170101136/profilerbench/sync
cpu: Intel(R) Xeon(R) Platinum 8269CY CPU @ 2.50GHz
BenchmarkChanProdConsWork0-8    10000000               839.0 ns/op
PASS
ok      github.com/zdyj3170101136/profilerbench/sync    8.490s

/root/go/bin/go test -run=^$ -bench=BenchmarkChanProdConsWork0$ -benchtime=10000000x -blockprofile=b
goos: linux
goarch: amd64
pkg: github.com/zdyj3170101136/profilerbench/sync
cpu: Intel(R) Xeon(R) Platinum 8269CY CPU @ 2.50GHz
BenchmarkChanProdConsWork0-8    10000000               793.7 ns/op
PASS
ok      github.com/zdyj3170101136/profilerbench/sync    8.059s

What did you expect to see?

with blockprofile, the program should run slower!

What did you see instead?

with blockprofile, the program run faster !

helpful information

here is the cpu profile diff:
截屏2022-12-15 下午3 23 00

  • saveblockevent cost lots of cpu.
  • runtime.lock save lots of cpu, which means contention is less.
@seankhliao seankhliao changed the title runtime/chan: with -test.blockprofile program run even faster. runtime: with -test.blockprofile program run even faster. Dec 15, 2022
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Dec 15, 2022
@thanm thanm added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Dec 15, 2022
@thanm
Copy link
Contributor

thanm commented Dec 15, 2022

@golang/runtime

@mknyszek
Copy link
Contributor

Since that benchmark is a microbenchmark, it's possible there's a scalability failure as it hammers on a particular lock. The CPU profile seems to suggest this. By adding in time between lock calls via the block profile operations, it actually eases up barging behaviors causing better performance.

I'm not sure there's anything to do here. In general, scalability failures aren't a good thing to have, but unless they're affecting real-world Go programs, I'm not too worried. They usually require a non-trivial amount of work to resolve, though this may be related to just general channel performance.

Please see #8899 for one possible solution/mitigation. Closing for now.

@mknyszek mknyszek closed this as not planned Won't fix, can't repro, duplicate, stale Dec 19, 2022
@mknyszek
Copy link
Contributor

(To be clear, I don't think we shouldn't make channels scale better in general. :) It's just going to be a non-trivial effort, potentially with a long bug tail, and we have to weigh that against everything else.)

@golang golang locked and limited conversation to collaborators Dec 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants