-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Description
Note, Oct 12 2022 Current proposal is #54714 (comment)
What version of Go are you using (go version
)?
go version go1.19 linux/arm64
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="arm64" GOBIN="" GOCACHE="/home/parallels/.cache/go-build" GOENV="/home/parallels/.config/go/env" GOEXE="" GOEXPERIMENT="" GOFLAGS="" GOHOSTARCH="arm64" GOHOSTOS="linux" GOINSECURE="" GOMODCACHE="/home/parallels/src/go/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="linux" GOPATH="/home/parallels/src/go" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/home/parallels/bin/go" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/home/parallels/bin/go/pkg/tool/linux_arm64" GOVCS="" GOVERSION="go1.19" GCCGO="gccgo" AR="ar" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="/home/parallels/src/go/src/golang.org/x/sys/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 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1413276320=/tmp/go-build -gno-record-gcc-switches"
What did you do?
In quic-go, we read control messages to read the ECN bits from the IP header, and to read the network interface index.
We parse the OOB bytes using unix.ParseSocketControlMessage
. See https://github.com/lucas-clemente/quic-go/blob/07412be8a02ef0e55580ebf8db9c38a759c0a0e5/sys_conn_oob.go#L166-L206 for the respective control message processing logic.
What did you expect to see?
Ideally, unix.ParseSocketControlMessage
would not allocate.
What did you see instead?
Receiving 1 GB of data using QUIC creates a huge amount of allocations (as determined using the allocs
function of pprof). Roughly 100 MB of those allocations come from unix.ParseSocketControlMessage
.
A simple back-of-the-envelope shows that this is roughly what we'd expect:
A data transfer of 1 GB requires receiving roughly 860,000 received packets, assuming a payload size of 1250 bytes per QUIC packet.
The []SocketControlMessage
slice allocates 24 bytes, and the size of each control message is 40 bytes. There are two control messages per packet (unix.IP_TOS
and unix.IP_PKTINFO
). Parsing the control messages therefore allocates of 104 bytes per packet, or 89 MB in total for the 1 GB transfer.
Proposal
It would be nice to have an API that allows parsing socket control message that doesn't allocate at all.
The following API would fulfill that property:
func ParseSocketControlMessageWithHandler(b []byte, handler func(message SocketControlMessage)) error
UPDATE: Submitted a fix https://go-review.googlesource.com/c/sys/+/425916.