From 53d4e5ee1735090a85421420f88b8d937b43c69a Mon Sep 17 00:00:00 2001 From: Matthew Jaffee Date: Tue, 31 Oct 2017 16:44:03 -0500 Subject: [PATCH 1/3] bump http client's MaxIdleConns and MaxIdleConnsPerHost The idea here is for Pilosa to behave better under high query load where a node might be making many connections to the other nodes in the cluster in order to support lots of concurrent batches of SetBit queries (for example). By allowing for more idle connections and more idle connections per host, we reduce connection churn, and allow more connections to be reused rather than creating new ones and potentially having many stale sockets in the TIME_WAIT state. See https://github.com/golang/go/issues/16012 --- executor.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/executor.go b/executor.go index a620a1145..fe9c42878 100644 --- a/executor.go +++ b/executor.go @@ -20,6 +20,7 @@ import ( "errors" "fmt" "io/ioutil" + "net" "net/http" "net/url" "sort" @@ -57,7 +58,21 @@ type Executor struct { // NewExecutor returns a new instance of Executor. func NewExecutor() *Executor { return &Executor{ - HTTPClient: http.DefaultClient, + HTTPClient: &http.Client{ + Transport: &http.Transport{ + Proxy: http.ProxyFromEnvironment, + DialContext: (&net.Dialer{ + Timeout: 30 * time.Second, + KeepAlive: 30 * time.Second, + DualStack: true, + }).DialContext, + MaxIdleConns: 1000, + MaxIdleConnsPerHost: 200, + IdleConnTimeout: 90 * time.Second, + TLSHandshakeTimeout: 10 * time.Second, + ExpectContinueTimeout: 1 * time.Second, + }, + }, } } From 17c90c7ec377378bc9f125a9c29f838bfe343cf0 Mon Sep 17 00:00:00 2001 From: Matthew Jaffee Date: Wed, 1 Nov 2017 11:32:57 -0500 Subject: [PATCH 2/3] decrease maxIdleConnsPerHost test were failing in CI --- executor.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/executor.go b/executor.go index fe9c42878..eb97a75af 100644 --- a/executor.go +++ b/executor.go @@ -67,7 +67,7 @@ func NewExecutor() *Executor { DualStack: true, }).DialContext, MaxIdleConns: 1000, - MaxIdleConnsPerHost: 200, + MaxIdleConnsPerHost: 80, IdleConnTimeout: 90 * time.Second, TLSHandshakeTimeout: 10 * time.Second, ExpectContinueTimeout: 1 * time.Second, From 97eef1ff9028b92685f17691973429c5a267c325 Mon Sep 17 00:00:00 2001 From: Matthew Jaffee Date: Wed, 1 Nov 2017 12:55:37 -0500 Subject: [PATCH 3/3] revert back to 200 idle conns per host CI error appears unrelated to this setting --- executor.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/executor.go b/executor.go index eb97a75af..fe9c42878 100644 --- a/executor.go +++ b/executor.go @@ -67,7 +67,7 @@ func NewExecutor() *Executor { DualStack: true, }).DialContext, MaxIdleConns: 1000, - MaxIdleConnsPerHost: 80, + MaxIdleConnsPerHost: 200, IdleConnTimeout: 90 * time.Second, TLSHandshakeTimeout: 10 * time.Second, ExpectContinueTimeout: 1 * time.Second,