Skip to content
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

*: drain http.Response.Body before closing #4880

Merged
merged 1 commit into from Mar 30, 2016
Merged

Conversation

gyuho
Copy link
Contributor

@gyuho gyuho commented Mar 28, 2016

Draining the body prevents the TCP/TLS connection from closing
and makes the connection available for reuse.

@gyuho
Copy link
Contributor Author

gyuho commented Mar 28, 2016

Won't do much speed-up since this is not in the critical path, I think. *_1 is the one with this patch. At least no regression?

bench-plot-avg-cpu
bench-plot-avg-latency-ms
bench-plot-avg-mem
bench-plot-throughput

(Reference google/go-github#317 (comment))

@@ -231,6 +232,7 @@ func getVersion(m *Member, rt http.RoundTripper) (*version.Versions, error) {
}
// etcd 2.0 does not have version endpoint on peer url.
if resp.StatusCode == http.StatusNotFound {
io.Copy(ioutil.Discard, resp.Body)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

grecefulClose(resp http.Response) {
   io.Copy()
   resp.Body.Close()
}

@gyuho
Copy link
Contributor Author

gyuho commented Mar 30, 2016

@xiang90 PTAL.


// gracefulClose drains http.Response.Body to prevent TCP/TLS connections
// from closing, then making it available for reuse.
func gracefulClose(resp *http.Response) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move this to pkg/httputil?

@gyuho
Copy link
Contributor Author

gyuho commented Mar 30, 2016

@xiang90 PTAL. Thanks!

@@ -19,6 +19,7 @@ import (
"encoding/binary"
"fmt"
"io"
"io/ioutil"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this line?

@xiang90
Copy link
Contributor

xiang90 commented Mar 30, 2016

LGTM after tests pass.

@gyuho
Copy link
Contributor Author

gyuho commented Mar 30, 2016

My goimports didn't work. Fixed. Will merge after green lights. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants