Re-enable HTTP keep-alives now that net/http is fixed (as of Go 1.6!) #10
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Way back in 2013 we had added a workaround to a net/http bug
(see golang/go#4677, particularly rogpeppe's
comment) that involved closing the connection after each request:
However, that net/http bug was fixed in 2016 (in
https://go-review.googlesource.com/c/go/+/3210/ which was included in
Go 1.6), so we can re-enable this and significantly speed subsequent
requests to the same host when using juju/http. For comparison, the
net/http package enables keep-alives by default; we had only disabled
them due to that bug.
Some numbers: a full request to the Charmhub API takes about 1s from
New Zealand (to London, I believe) due mainly to latency from the
initial TLS negotiation. With DisableKeepAlives, subsequent requests
were of course taking the same time -- now subsequent requests take
only ~350ms.
Also add tests to ensure DisableKeepAlives is off by default -- doesn't
really test the feature (that's "too hard" to do well), but at least
ensures the correct values are being passed to http.Transport.