golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
123.67k stars 17.62k forks source link

x/net/http2: improve frame decoding performance by reusing frames #68352

Open YHM404 opened 3 months ago

YHM404 commented 3 months ago

Proposal Details

I noticed a issue about SetReuseFrames https://github.com/golang/go/issues/18502

I would like to propose the addition of a configuration option to enable or disable SetReuseFrames in the HTTP2 server and HTTP2 transport.

SetReuseFrames has been shown to improve the performance of go-grpc, so I believe it can similarly enhance the performance of HTTP server/client.

By adding this configuration option, users can choose to enable frame reuse based on their performance needs and use cases.

Thank you for considering this feature request.

gabyhelp commented 3 months ago

Related Issues and Documentation

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

ianlancetaylor commented 3 months ago

CC @neild @bradfitz

neild commented 3 months ago

There's no need for a user-configurable option here. If there are performance improvements that can be made to frame decoding in the HTTP/2 implementation, we can just make them.

YHM404 commented 3 months ago

There's no need for a user-configurable option here. If there are performance improvements that can be made to frame decoding in the HTTP/2 implementation, we can just make them.

I will conduct a performance comparison and, if everything looks good, I will submit a pull request.

YHM404 commented 3 months ago

I have conducted a simple benchmark, and the results show that SetReuseFrames significantly improves the performance of parseDataFrame.

Running tool: /usr/local/bin/go test -benchmem -run=^$ -bench ^BenchmarkParseDataFramesWithoutReuse$ golang.org/x/net/http2

goos: darwin
goarch: amd64
pkg: golang.org/x/net/http2
cpu: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
BenchmarkParseDataFramesWithoutReuse-12     31313877            39.03 ns/op       48 B/op          1 allocs/op
Running tool: /usr/local/bin/go test -benchmem -run=^$ -bench ^BenchmarkParseDataFrames$ golang.org/x/net/http2

goos: darwin
goarch: amd64
pkg: golang.org/x/net/http2
cpu: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
BenchmarkParseDataFrames-12     143745076            8.167 ns/op           0 B/op          0 allocs/op
PASS
ok      golang.org/x/net/http2  2.413s