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

GOMAXPROCS not work #42845

Closed
qiaohao9 opened this issue Nov 26, 2020 · 3 comments
Closed

GOMAXPROCS not work #42845

qiaohao9 opened this issue Nov 26, 2020 · 3 comments

Comments

@qiaohao9
Copy link

qiaohao9 commented Nov 26, 2020

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

$ go version
go version go1.15.5 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="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/xxx/.cache/go-build"
GOENV="/home/xx/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/xxx/.go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/xxx/.go"
GOPRIVATE=""
GOPROXY="https://goproxy.cn,direct"
GOROOT="/usr/lib/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/xxx/gRPC-tutorial/go.mod"
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build338536254=/tmp/go-build -gno-record-gcc-switches"

What did you do?

My CPU nums:

$ echo "Threads/core: $(nproc --all)"
Threads/core: 4

Go Playground

What did you expect to see?

It should cost 6s.

What did you see instead?

It cost 3s.

@go101
Copy link

go101 commented Nov 26, 2020

Why should it cost 6s?

All 8 goroutines are running simultaneously. The result should be unrelated to GOMAXPROCS.

@mpx
Copy link
Contributor

mpx commented Nov 26, 2020

GOMAXPROCS limits the number of OS threads used to actively run Goroutines. The goroutines in your example spend almost all their time sleeping (not running) . GOMAXPROCS will make more of a difference if your workers are performing a fixed amount of heavy computation instead.

I'd recommend asking these questions on the Gopher Slack forum, or golang-nuts. This issue tracker is intended for developing the Go toolchain and related projects.

@ALTree
Copy link
Member

ALTree commented Nov 26, 2020

As it was pointed out, there's no reason to expect the program to take 6s: all the goroutines just sleep for 3s an then the program ends. GOMAXPROCS' value makes no difference here. Closing, since this is not a bug in Go.

@ALTree ALTree closed this as completed Nov 26, 2020
@golang golang locked and limited conversation to collaborators Nov 26, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants