From 07400f9d2b87b2ad5f7b1aa68d554a2251e8d370 Mon Sep 17 00:00:00 2001 From: Wojciech Tyczynski Date: Mon, 27 Apr 2015 10:10:12 +0200 Subject: [PATCH] Increase maxIdleConnection limit in etcd client. --- cmd/kube-apiserver/app/server.go | 12 ++++++- .../forked/coreos/go-etcd/etcd/client.go | 32 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 third_party/forked/coreos/go-etcd/etcd/client.go diff --git a/cmd/kube-apiserver/app/server.go b/cmd/kube-apiserver/app/server.go index 02831b96c667f..de01550aff4ef 100644 --- a/cmd/kube-apiserver/app/server.go +++ b/cmd/kube-apiserver/app/server.go @@ -39,6 +39,7 @@ import ( "github.com/GoogleCloudPlatform/kubernetes/pkg/master" "github.com/GoogleCloudPlatform/kubernetes/pkg/tools" "github.com/GoogleCloudPlatform/kubernetes/pkg/util" + forked "github.com/GoogleCloudPlatform/kubernetes/third_party/forked/coreos/go-etcd/etcd" "github.com/coreos/go-etcd/etcd" "github.com/golang/glog" @@ -192,7 +193,16 @@ func newEtcd(etcdConfigFile string, etcdServerList util.StringList, storageVersi return helper, err } } else { - client = etcd.NewClient(etcdServerList) + etcdClient := etcd.NewClient(etcdServerList) + transport := &http.Transport{ + Dial: forked.Dial, + TLSClientConfig: &tls.Config{ + InsecureSkipVerify: true, + }, + MaxIdleConnsPerHost: 500, + } + etcdClient.SetTransport(transport) + client = etcdClient } return master.NewEtcdHelper(client, storageVersion, pathPrefix) diff --git a/third_party/forked/coreos/go-etcd/etcd/client.go b/third_party/forked/coreos/go-etcd/etcd/client.go new file mode 100644 index 0000000000000..7826be8066393 --- /dev/null +++ b/third_party/forked/coreos/go-etcd/etcd/client.go @@ -0,0 +1,32 @@ +package etcd + +import ( + "errors" + "net" + "time" +) + +// dial attempts to open a TCP connection to the provided address, explicitly +// enabling keep-alives with a one-second interval. +func Dial(network, addr string) (net.Conn, error) { + conn, err := net.DialTimeout(network, addr, time.Second) + if err != nil { + return nil, err + } + + tcpConn, ok := conn.(*net.TCPConn) + if !ok { + return nil, errors.New("Failed type-assertion of net.Conn as *net.TCPConn") + } + + // Keep TCP alive to check whether or not the remote machine is down + if err = tcpConn.SetKeepAlive(true); err != nil { + return nil, err + } + + if err = tcpConn.SetKeepAlivePeriod(time.Second); err != nil { + return nil, err + } + + return tcpConn, nil +}