4869: Enable TCP keepalive and adjust connection timeouts to Keep client.
authorPeter Amstutz <peter.amstutz@curoverse.com>
Tue, 30 Dec 2014 15:39:50 +0000 (10:39 -0500)
committerPeter Amstutz <peter.amstutz@curoverse.com>
Tue, 30 Dec 2014 15:39:50 +0000 (10:39 -0500)
sdk/go/keepclient/keepclient.go
sdk/go/keepclient/support.go

index df6fee12914ed0218ce076bcc6d9d5e717a659c1..dbc24666393a4c7d866702abd77c5b438ec9d0db 100644 (file)
@@ -10,6 +10,7 @@ import (
        "io"
        "io/ioutil"
        "log"
+       "net"
        "net/http"
        "regexp"
        "strings"
@@ -48,7 +49,22 @@ func MakeKeepClient(arv *arvadosclient.ArvadosClient) (kc KeepClient, err error)
                Arvados:       arv,
                Want_replicas: 2,
                Using_proxy:   false,
-               Client:        &http.Client{Transport: &http.Transport{}}}
+               Client: &http.Client{
+                       // The maximum duration of the connection, will be
+                       // closed if exceeded.
+                       Timeout: 5 * time.Minute,
+                       Transport: &http.Transport{
+                               Dial: (&net.Dialer{
+                                       // The maximum time to wait to set up
+                                       // the initial TCP connection.
+                                       Timeout: 60 * time.Second,
+
+                                       // The TCP keep alive heartbeat
+                                       // interval.
+                                       KeepAlive: 60 * time.Second,
+                               }).Dial,
+                               TLSHandshakeTimeout: 10 * time.Second,
+                       }}}
 
        err = (&kc).DiscoverKeepServers()
 
index c03578c5d3d868021e6e7f53460838409f172d31..a2787c5441cefca4ebdcb0300da15a6741036ace 100644 (file)
@@ -9,6 +9,7 @@ import (
        "io"
        "io/ioutil"
        "log"
+       "net"
        "net/http"
        "os"
        "strings"
@@ -33,13 +34,29 @@ func (this *KeepClient) DiscoverKeepServers() error {
                this.SetServiceRoots(sr)
                this.Using_proxy = true
                if this.Client.Timeout == 0 {
-                       this.Client.Timeout = 10 * time.Minute
+                       // See MakeKeepClient for notes on meaning of timeouts.
+                       this.Client.Timeout = 300 * time.Second
+                       this.Client.Transport = &http.Transport{
+                               Dial: (&net.Dialer{
+                                       Timeout:   30 * time.Second,
+                                       KeepAlive: 60 * time.Second,
+                               }).Dial,
+                               TLSHandshakeTimeout: 10 * time.Second,
+                       }
                }
                return nil
        }
 
        if this.Client.Timeout == 0 {
-               this.Client.Timeout = 15 * time.Second
+               // See MakeKeepClient for notes on meaning of timeouts.
+               this.Client.Timeout = 20 * time.Second
+               this.Client.Transport = &http.Transport{
+                       Dial: (&net.Dialer{
+                               Timeout:   2 * time.Second,
+                               KeepAlive: 60 * time.Second,
+                       }).Dial,
+                       TLSHandshakeTimeout: 10 * time.Second,
+               }
        }
 
        type svcList struct {