net/http: performance degradation when sending HTTP request with bytes.Reader #44759
Labels
FrozenDueToAge
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Performance
Milestone
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: