From db9e83de628fb1b1e0369557936ca015d82180e2 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Tue, 20 Feb 2018 12:23:37 -0800 Subject: [PATCH] Avoid significant connections in TIME_WAIT (#5555) MaxIdleConns limits the total number of connections kept in the pool for re-use. In addition, MaxIdleConnsPerHost limits the number for a single host. Since minio gateways usually connect to the same host, setting `MaxIdleConns = 100` won't really have much of an impact since the idle connection pool is limited to 2 anyway. Now, with the pool set to a limit of 2, and when using the client heavily from 2+ goroutines, the `http.Transport` will open a connection, use it, then try to return it to the idle-pool which often fails since there's a limit of 2. So it's going to close the connection and new ones will be opened on demand again, many of which get closed soon after being used. Since those connections/sockets don't disappear from the OS immediately, use `MaxIdleConnsPerHost = 100` which fixes this problem. --- cmd/utils.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cmd/utils.go b/cmd/utils.go index 410fa23ac..0602113c9 100644 --- a/cmd/utils.go +++ b/cmd/utils.go @@ -246,8 +246,8 @@ func ToS3ETag(etag string) string { // NewCustomHTTPTransport returns a new http configuration // used while communicating with the cloud backends. -// This sets the value for MaxIdleConns from 2 (go default) to -// 100. +// This sets the value for MaxIdleConnsPerHost from 2 (go default) +// to 100. func NewCustomHTTPTransport() http.RoundTripper { return &http.Transport{ Proxy: http.ProxyFromEnvironment, @@ -256,6 +256,7 @@ func NewCustomHTTPTransport() http.RoundTripper { KeepAlive: 30 * time.Second, }).DialContext, MaxIdleConns: 100, + MaxIdleConnsPerHost: 100, IdleConnTimeout: 90 * time.Second, TLSHandshakeTimeout: 10 * time.Second, ExpectContinueTimeout: 1 * time.Second,