-
Notifications
You must be signed in to change notification settings - Fork 18k
x/net/http2: decrease memory consumption when small request coming #18509
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
Comments
After some |
CL https://golang.org/cl/34754 mentions this issue. |
In our benchmark, after modification, heap size is no large than 1GB. |
/cc @bradfitz |
This is effectively a dup of #16512, especially this comment, which notes that we'll need a smarter buffering strategy to support connection-wide flow control. With the suggested limit of 1MB per connection from #16512, and 1000 concurrent connections ( |
@tombergan Although the result is similar with #16512, the implementation is quite different, i do not use any per connection memory limit, but use existing Content-Length header from requests. If i change the size of testdata to smaller like 100 bytes or larger like 4KB, the heap size will change too. |
Yes, thanks for the report. We need to rethink the buffering strategy to better share the connection's flow window across all requests. As you point out, we should minimize the amount of memory allocated to individual requests, rather than blindly allocating 64KB to every request. However, I think we'd implement that slightly differently than in your sample CL, by trying to do a better job of reusing buffers for multiple requests so each POST doesn't require an allocation. |
@tombergan I am very looking foward to your job, we have a very h2 traffic and quite need any cpu and memory optimization. |
CL https://golang.org/cl/37400 mentions this issue. |
fixedBuffer was a bad idea for two reasons: 1. It was fixed at a constant 64KB (the current default flow-control window) which wastes memory on the server when clients upload many small request bodies. 2. A follow-up CL will allow configuring the server's connection and stream receive windows. We want to allow individual streams to use varying amounts of the available connection window. This is not possible when each stream uses a fixedBuffer. dataBuffer grows and shrinks based on current usage. The worst-case fragmentation of dataBuffer is 32KB wasted memory per stream, but I expect that worst-case will be rare. In particular, if the declared size of a stream's request body is under 1KB, then the server will not allocate more than 1KB to process that stream's request body. Updates golang/go#16512 Fixes golang/go#18509 Change-Id: Ibcb18007037e82518a65848ef3baf4937955ac9d Reviewed-on: https://go-review.googlesource.com/37400 Run-TryBot: Tom Bergan <tombergan@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?What operating system and processor architecture are you using (
go env
)?What did you do?
Use following to benchmark:
h2load -n 10000000 -c 1000 -m 100 -d ~/testdata http://127.0.0.1:8088/
~/testdata
file is 950 bytes large.What did you expect to see?
Use
ps
andtop
to see memory consumption, and not very large.What did you see instead?
Memory consumption can go up to 8GB

The text was updated successfully, but these errors were encountered: