From 7fcbd3fa4b8501ce535b54576b33f8ce8d99c991 Mon Sep 17 00:00:00 2001 From: Roman Khavronenko Date: Wed, 13 Oct 2021 17:29:28 +0300 Subject: [PATCH] Adjust `http.Transport.MaxIdleConns` setting for vmauth/vmalert services (#1704) * vmalert: adjust `http.Transport.MaxIdleConns` value accordingly to `http.Transport.MaxIdleConnsPerHost` `http.Transport.MaxIdleConnsPerHost` setting is controlled by `datasource.maxIdleConnections` flag, while `http.Transport.MaxIdleConns` is inherited from DefaultTransport and is equal to `100`. The fix adjusts `http.Transport.MaxIdleConns` value if it is lower than `http.Transport.MaxIdleConnsPerHost`. Signed-off-by: hagen1778 * vmauth: adjust `http.Transport.MaxIdleConns` value accordingly to `http.Transport.MaxIdleConnsPerHost` `http.Transport.MaxIdleConnsPerHost` setting is controlled by `maxIdleConnsPerBackend` flag, while `http.Transport.MaxIdleConns` is inherited from DefaultTransport and is equal to `100`. The fix adjusts `http.Transport.MaxIdleConns` value if it is lower than `http.Transport.MaxIdleConnsPerHost`. Signed-off-by: hagen1778 --- app/vmalert/datasource/init.go | 3 +++ app/vmauth/main.go | 3 +++ 2 files changed, 6 insertions(+) diff --git a/app/vmalert/datasource/init.go b/app/vmalert/datasource/init.go index 3e28d6e43..72cfddfc9 100644 --- a/app/vmalert/datasource/init.go +++ b/app/vmalert/datasource/init.go @@ -52,6 +52,9 @@ func Init(extraParams []Param) (QuerierBuilder, error) { return nil, fmt.Errorf("failed to create transport: %w", err) } tr.MaxIdleConnsPerHost = *maxIdleConnections + if tr.MaxIdleConns != 0 && tr.MaxIdleConns < tr.MaxIdleConnsPerHost { + tr.MaxIdleConns = tr.MaxIdleConnsPerHost + } if *roundDigits > 0 { extraParams = append(extraParams, Param{ diff --git a/app/vmauth/main.go b/app/vmauth/main.go index e1b282bec..22cd16ae5 100644 --- a/app/vmauth/main.go +++ b/app/vmauth/main.go @@ -130,6 +130,9 @@ var reverseProxy = &httputil.ReverseProxy{ // Disable HTTP/2.0, since VictoriaMetrics components don't support HTTP/2.0 (because there is no sense in this). tr.ForceAttemptHTTP2 = false tr.MaxIdleConnsPerHost = *maxIdleConnsPerBackend + if tr.MaxIdleConns != 0 && tr.MaxIdleConns < tr.MaxIdleConnsPerHost { + tr.MaxIdleConns = tr.MaxIdleConnsPerHost + } return tr }(), FlushInterval: time.Second,