go: crypto/tls: 500% increase in allocations from `(*tls.Conn).Read` in go 1.17
What version of Go are you using (go version
)?
$ go version 1.17.3
Does this issue reproduce with the latest release?
I believe so, but have not yet confirmed.
What operating system and processor architecture are you using (go env
)?
go env
Output
$ go env GOARCH="amd64" GOOS="linux"
What did you do?
I’m running a service that has many http2 clients.
What did you expect to see?
Fewer allocations when reading data from established connections.
What did you see instead?
Around 20-25% of our service’s total allocations at times are coming from context.WithCancel
calls made by (*tls.Conn).handshakeContext
.
It looks like every (*tls.Context).Read
call made by http2’s ReadFrame
is calling c.Handshake
which calls through to c.handshakeContext
, which begins with a call to context.WithCancel
, which allocates.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 3
- Comments: 15 (10 by maintainers)
As mentioned in the Gophers Slack discussion, it seems to me we could simply move the early exit checks above the context manipulation functions to remove these allocations in the case where the handshake has already completed.
Thanks @dt and @FiloSottile for getting this in ❤️
I did a quick run comparing
release-branch.go1.16
andrelease-branch.go1.17
usingcrypto/tls.BenchmarkThroughput
. The raw timing numbers across those two are not directly comparable, as an unrelated change in 9d0819b27 switched the cipher config to avoid hardware aes, but just looking at the allocations / op:By looking at 1.16 vs 90d6bbbe42c15d4 – the last commit to touch
crypto/tls
commit prior to the cipher change above – I think we can see what effect these extra allocations have on the actual performance:Is this enough of a regression to justify a backport?
I’m unclear as to whether or not the performance regression seen here qualifies for a backport under the backport policy’s definition of a serious issue with no workaround:
I’ll go ahead and open backport issues to continue the discussion there I guess?
@gopherbot please consider this for backport to 1.17, as it is a regression compared to 1.16.
@gopherbot please consider this for backport to 1.18, as it is a regression compared to 1.16.
Is there any update on this issue?