Skip to content

runtime: unnecessary return in netpoll #49026

Open
@zhouguangyuan0718

Description

@zhouguangyuan0718

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

$ go version
go version go1.17.1 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="/root/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/root/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/mnt/d/00.Tool/00.golang/go1.17"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/mnt/d/00.Tool/00.golang/go1.17/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.17.1"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/mnt/d/01.Project/03.go_performance/demo/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-build2033964888=/tmp/go-build -gno-record-gcc-switches"

What did you do?

server.go:

package main

import (
	"log"
	"net"
	"net/http"
	_ "net/http/pprof"
	"time"
)

func init() {
	go func() {
		http.ListenAndServe("127.0.0.1:6060", nil)
	}()
	// backend
	go func() {
		http.ListenAndServe("127.0.0.1:6061", nil)
	}()
}

func main() {

	l, err := net.Listen("tcp", "127.0.0.1:3000")
	if err != nil {
		panic(err)
	}
	for {
		c, err := l.Accept()
		if err != nil {
			panic(err)
		}
		r := make([]byte, 50)
		for {
			time.Sleep(50 * time.Millisecond)
			n, err := c.Read(r)
			log.Println(n, err)
		}
	}
}

client.go

package main

import (
	"net"
	"time"
)

func main() {
	c, err := net.Dial("tcp", "127.0.0.1:3000")
	if err != nil {
		panic(err)
	}
	for {
		time.Sleep(time.Millisecond)
		c.Write([]byte{'c'})
	}
}

And excute these command:

$ go run server.go
$ go run client.go
$ curl  http://127.0.0.1:6060/debug/pprof/trace?seconds=5 -o trace.data
$ go tool trace trace.data

What did you expect to see?

In trace view, the event "proc start" and "proc stop" should appear every 50 ms because of time.Sleep(50 * time.Millisecond).

What did you see instead?

The event "proc start" and "proc stop" appears every 1 ms because of client sends data every 1 ms.
image
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Performancecompiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    Status

    Triage Backlog

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions