From 53d4e5ee1735090a85421420f88b8d937b43c69a Mon Sep 17 00:00:00 2001 From: Matthew Jaffee Date: Tue, 31 Oct 2017 16:44:03 -0500 Subject: [PATCH] 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, + }, + }, } }