net/http: performance degradation when sending HTTP request with bytes.Reader #44759
Labels
Milestone
Comments
I don't believe the suggested fix is sufficient. The problem isn't that the I'm not certain what the correct behavior is here. I wonder if |
Filed #44815 to propose the |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Sending a HTTP PUT request with bytes.Reader
There is a significant performance degradation due to some problems with the
net/http
.Simple analysis:
The http.DefaultClient.Do call will eventually go to io.Copy.
In this case, dst is a
*bufio.Writer
, and src is anioutil.nopCloser
. And, in thecopyBuffer
,bufio.Writer.ReadFrom
will be called. Inbufio.Writer.ReadFrom
, becasue some headers have been written tob.buf
and not beenFlush
, the for loop will be executed. In this loop, it will only copy 4KiB tob.buf
each time, resulting in useless memory copies and a large number of system calls, which in turn leads to performance degradation.Suggested fix
use
instead of
.
The text was updated successfully, but these errors were encountered: