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
net/http: http/2 throughput is very slow compared to http/1.1 #47840
Comments
You're comparing encrypted HTTP/2 with unencrypted HTTP. You need to compare HTTP/2 with HTTPS to compare like with like. |
hi, the POC is using H2C to avoid encryption. |
Caddy a web server written in Go has the same issue. I've updated the POC with a sample Caddy config: https://github.com/nspeed-app/http2issue/tree/main/3rd-party/Caddy |
Apologies, I missed this in the original issue and didn't see the followup. I have not had time to look at this further, adding to my queue. (But no promises on timing.) |
Wouldn‘t the first step be to run this against a non-go server/client to localize it on either side if possible? |
Robert Engels has a CL related to this https://go-review.googlesource.com/c/net/+/362834 |
Copying my comment from https://groups.google.com/d/msgid/golang-nuts/89926c2f-ec73-43ad-be49-a8bc76a18345n%40googlegroups.com Http2 is a multiplexed protocol with independent streams. The Go implementation uses a common reader thread/routine to read all of the connection content, and then demuxes the streams and passes the data via pipes to the stream readers. This multithreaded nature requires the use of locks to coordinate. By managing the window size, the connection reader should never block writing to a steam buffer - but a stream reader may stall waiting for data to arrive - get descheduled - only to be quickly rescheduled when reader places more data in the buffer - which is inefficient. Out of the box on my machine, http1 is about 37 Gbps, and http2 is about 7 Gbps on my system. Some things that jump out:
I made some local mods to the net library, increasing the frame size to 256k, and the http2 performance went from 8Gbps to 38Gbps.
So 38Gbps for http2 vs 55 Gbps for http1. Better but still not great. Still, with some minor changes, the net package could allow setting of a large frame size on a per stream basis - which would enable much higher throughput. The gRPC library allows this. |
My CL goes a long way to addressing the issue. Still, some additional testing has shown that the calls to update the window from the client (the downloader) don't seem to be optimal for large transfers - even with the 10x frame size. The window update calls cause contention on the locks. |
Changing trasport.go:2418 from Ideally, this code would make the determination based on receive and consume rates along with the frame size. |
I don't know if you are referring to this buffer in one of your comments, but using the profiler it shows a lot of contention on the Lines 3465 to 3468 in 0e1d553
Increasing the value there to the maxFrameSize value, and using the shared code in the description, you can go from 6Gbps to 12.6 Gbps |
As I pointed out above, increasing the frame size can achieve 38 Gbps. The issue is that constant is used for all connections. The 'max frame size' is connection dependent. More importantly, that constant does not exist in golang.org/x/net/http - which is the basis of the future version. |
yeah, I've should explained myself better, sorry, in addition to increase the frame size that require manual configuration, it is an user decision to maximize throughput, I just wanted to add that maybe we can improve the default throughput with that change, since it is clear that the author left open that parameter to debate and it is a 2x win (at a cost of increasing memory cost of course, but this is inside a sync.Pool that may alleviate this problem a bit)
it does, just with a different name https://github.com/golang/net/blob/0fccb6fa2b5ce302a9da5afc2513d351bd175889/http2/http2.go#L256-L259 IIUIC the http2 code in golang/go is a bundle created from the x/net/http2 |
Thanks for the excellent analysis! Ideally, we shouldn't require the user to twiddle configuration parameters to get good performance. However, making the maximum client-initiated frame size user-configurable seems like a reasonable first step. |
Change https://golang.org/cl/362834 mentions this issue: |
any update to this ? is someone at Google even working on this or is there no point waiting ? |
There has been a CL submitted - it is stuck in review. |
What version of Go are you using (
go version
)?1.7
Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?Linux, Windows, etc
go env
OutputWhat did you do?
test http/2 vs http1.1 transfert speed with client and server from standard lib
see a complete POC here: https://github.com/nspeed-app/http2issue
The issue is general, loopback (localhost) or over the wire.
What did you expect to see?
same speed order than http1.1
What did you see instead?
http/2 is at least x5 slower or worst
The text was updated successfully, but these errors were encountered: