From 632e00b5ee79d1a4a6f0dfc16c3306dc43e432f9 Mon Sep 17 00:00:00 2001 From: Chris Hager Date: Fri, 5 Apr 2024 11:21:53 +0200 Subject: [PATCH 1/2] improved proxy http client setup --- server/node_notee.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/server/node_notee.go b/server/node_notee.go index eaa2c38..4755f7b 100644 --- a/server/node_notee.go +++ b/server/node_notee.go @@ -36,7 +36,15 @@ func NewNode(log *zap.SugaredLogger, uri string, jobC chan *SimRequest, numWorke AddedAt: time.Now(), jobC: jobC, numWorkers: numWorkers, - client: &http.Client{}, + client: &http.Client{ + Timeout: ProxyRequestTimeout, + Transport: &http.Transport{ + MaxIdleConns: 100, + MaxConnsPerHost: 100, + MaxIdleConnsPerHost: 100, + IdleConnTimeout: 90 * time.Second, + }, + }, } return node, nil } From 9f8566b6ce3a44958342632a3aeebdc4175ec606 Mon Sep 17 00:00:00 2001 From: Chris Hager Date: Fri, 5 Apr 2024 11:27:02 +0200 Subject: [PATCH 2/2] configurable --- server/consts.go | 9 +++++++++ server/node_notee.go | 8 ++++---- server/node_tee.go | 7 ++++++- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/server/consts.go b/server/consts.go index 4c6eb77..14b2812 100644 --- a/server/consts.go +++ b/server/consts.go @@ -27,6 +27,11 @@ var ( RedisPrefix = GetEnv("REDIS_PREFIX", "prio-load-balancer:") // All redis keys will be prefixed with this EnableErrorTestAPI = os.Getenv("ENABLE_ERROR_TEST_API") == "1" // will enable /debug/testLogLevels which prints errors and ends with a panic (also enabled if mock-node is used) EnablePprof = os.Getenv("ENABLE_PPROF") == "1" // will enable /debug/pprof + + ProxyMaxIdleConns = GetEnvInt("ProxyMaxIdleConns", 100) + ProxyMaxConnsPerHost = GetEnvInt("ProxyMaxConnsPerHost", 100) + ProxyMaxIdleConnsPerHost = GetEnvInt("ProxyMaxIdleConnsPerHost", 100) + ProxyIdleConnTimeout = time.Duration(GetEnvInt("ProxyIdleConnTimeout", 90)) * time.Second ) func LogConfig(log *zap.SugaredLogger) { @@ -44,5 +49,9 @@ func LogConfig(log *zap.SugaredLogger) { "RedisPrefix", RedisPrefix, "EnableErrorTestAPI", EnableErrorTestAPI, "EnablePprof", EnablePprof, + "ProxyMaxIdleConns", ProxyMaxIdleConns, + "ProxyMaxConnsPerHost", ProxyMaxConnsPerHost, + "ProxyMaxIdleConnsPerHost", ProxyMaxIdleConnsPerHost, + "ProxyIdleConnTimeout", ProxyIdleConnTimeout, ) } diff --git a/server/node_notee.go b/server/node_notee.go index 4755f7b..0b0e961 100644 --- a/server/node_notee.go +++ b/server/node_notee.go @@ -39,10 +39,10 @@ func NewNode(log *zap.SugaredLogger, uri string, jobC chan *SimRequest, numWorke client: &http.Client{ Timeout: ProxyRequestTimeout, Transport: &http.Transport{ - MaxIdleConns: 100, - MaxConnsPerHost: 100, - MaxIdleConnsPerHost: 100, - IdleConnTimeout: 90 * time.Second, + MaxIdleConns: ProxyMaxIdleConns, + MaxConnsPerHost: ProxyMaxConnsPerHost, + MaxIdleConnsPerHost: ProxyMaxIdleConnsPerHost, + IdleConnTimeout: ProxyIdleConnTimeout, }, }, } diff --git a/server/node_tee.go b/server/node_tee.go index 80b12cf..757e51d 100644 --- a/server/node_tee.go +++ b/server/node_tee.go @@ -109,8 +109,13 @@ func NewNode(log *zap.SugaredLogger, uri string, jobC chan *SimRequest, numWorke return nil, err } client = http.Client{ + Timeout: ProxyRequestTimeout, Transport: &http.Transport{ - TLSClientConfig: tlsConfig, + TLSClientConfig: tlsConfig, + MaxIdleConns: ProxyMaxIdleConns, + MaxConnsPerHost: ProxyMaxConnsPerHost, + MaxIdleConnsPerHost: ProxyMaxIdleConnsPerHost, + IdleConnTimeout: ProxyIdleConnTimeout, }, } }