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

Merged
merged 1 commit into from Mar 14, 2017

Conversation

Projects
None yet
2 participants
@gbrayut
Contributor

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

cmd/scollector/collectors/interval.go
@@ -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 {

This comment has been minimized.

@alienth

alienth Mar 14, 2017

Contributor

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.

@alienth

alienth Mar 14, 2017

Contributor

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
@@ -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

This comment has been minimized.

@alienth

alienth Mar 14, 2017

Contributor

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

@alienth

alienth Mar 14, 2017

Contributor

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

@alienth

This comment has been minimized.

Show comment
Hide comment
@alienth

alienth Mar 14, 2017

Contributor

@gbrayut A couple nitpick comments, otherwise lgtm.

Contributor

alienth commented Mar 14, 2017

@gbrayut A couple nitpick comments, otherwise lgtm.

misc: Add io.CopyN calls before Body.Close calls so connection can be…
… 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

This comment has been minimized.

Show comment
Hide comment
@gbrayut

gbrayut Mar 14, 2017

Contributor

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.

Contributor

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

2 of 3 checks passed

continuous-integration/travis-ci/push The Travis CI build is in progress
Details
bosun All checks Passed!
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@gbrayut gbrayut deleted the drain branch Mar 14, 2017

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