diff --git a/pkg/http/client.go b/pkg/http/client.go index bd9682f..2b73621 100644 --- a/pkg/http/client.go +++ b/pkg/http/client.go @@ -124,6 +124,11 @@ func NewHTTPClient(token string, maxRetries int, timeoutSecs int, ensureIPv6Host } } + maxConnections := cfg.GetNumOfWorkers() + if maxConnections > 32 { + maxConnections = 32 + } + if cfg.ShouldForceIPv6() { ipv6List, err := hosts.FetchHosts(hosts.IPV6) if err != nil { @@ -135,6 +140,8 @@ func NewHTTPClient(token string, maxRetries int, timeoutSecs int, ensureIPv6Host } client.client.Transport = &http.Transport{ + MaxIdleConns: maxConnections, + MaxConnsPerHost: maxConnections, DialContext: func(ctx context.Context, network, address string) (net.Conn, error) { if ipv6Address, ok := client.ipv6.Get(address); ok { return dialer.Dial(network, ipv6Address) @@ -159,6 +166,8 @@ func NewHTTPClient(token string, maxRetries int, timeoutSecs int, ensureIPv6Host } } else { client.client.Transport = &http.Transport{ + MaxIdleConns: maxConnections, + MaxConnsPerHost: maxConnections, DialContext: func(ctx context.Context, network, address string) (net.Conn, error) { return dialer.Dial(network, address) },