Connections are indeed reused where possible by default in the Go standard
library.
But as http (before http2) does not support multiplexing, it is not
possible to reuse
a connection which is still in use (i.e. which is still in the process of
reading the response).
These means that the body of the http response does need to be read till
completion
and then closed by the client.
So you will want to do something like
for i := 0; i < 10; i++ {
r, err := client.Get("https://foo.com")
if err != nil {
panic(err)
}
io.Copy(os.Stdout, r)
r.Close()
}
Hope this helps....
- Amnon
On Wednesday, 6 May 2020 19:01:55 UTC+1, Ryan Rank wrote:
>
> I wrote a small program that runs a repeated GET against a given URL.
> However, the DisableKeepAlives boolean does not seem to be honored. Code is
> similar to this:
>
> transport := &http.Transport{
> DisableKeepAlives: false,
> }
>
> client := &http.Client{
> Transport: transport,
> }
>
> for i := 0; i < 10; i++ {
> _, err := client.Get("https://foo.com")
> }
>
> Based on the code, I would expect the HTTP session to stay alive. I ran
> the preceding code with keepalive enabled and disabled, performance was not
> impacted. I then did a TCPDump and saw that the TCP session was being built
> and torn down with every HTTP Request. I have a feeling that I'm missing
> something. Does anyone have any ideas?
>
> Go 1.11.1 on CentOS 7
>
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/golang-nuts/892d54fe-3e60-438e-8e1e-d8a72b22ba3c%40googlegroups.com.