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

misc: Drain body responses so that connection is eligible for reuse #2036

Merged
merged 1 commit into from
Mar 14, 2017

Conversation

gbrayut
Copy link
Contributor

@gbrayut gbrayut commented Mar 13, 2017

After Jason updated tsdbrelay I did an audit of the various places we use Body.Close but don't read any bytes. This should allow connection reuse in those cases. Testing on ny-gbraylx01 but would like someone to review @captncraig @alienth @kylebrandt

@@ -111,6 +112,10 @@ func enableURL(url string, regexes ...string) func() bool {
return false
}
defer resp.Body.Close()
if resp.StatusCode != 200 || len(res) == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could just batch this up in an anonymous defer func rather than having this awkward condition here that mirrors future conditions. Since we ignore errors intentionally from CopyN in this case, doesn't matter if a ReadAll has already occurred.

Just a nitpick, tho. Fine as is if you'd prefer.

collect/queue.go Outdated
@@ -138,6 +139,8 @@ func sendBatch(batch []*opentsdb.DataPoint) {
time.Sleep(d)
return
}
// Drain up to 512 bytes and close the body to let the Transport reuse the connection
Copy link
Contributor

Choose a reason for hiding this comment

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

Comment here is semi-erroneous since we don't exactly close the body here.

@alienth
Copy link
Contributor

alienth commented Mar 14, 2017

@gbrayut A couple nitpick comments, otherwise lgtm.

… reused

I did an audit of the varous places we use Body.Close but don't read any bytes. This should allow connection reuse in those cases.
@gbrayut
Copy link
Contributor Author

gbrayut commented Mar 14, 2017

I changed interval.go to use an anon func as that is cleaner. I also updated the comment in queue.go to be clearer. I will do some more testing on scollector dev and then rollout tsdbrelay later tonight.

@gbrayut gbrayut merged commit e354eb2 into master Mar 14, 2017
@gbrayut gbrayut deleted the drain branch March 14, 2017 21:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants