Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config http client idle connections #671

Merged
merged 3 commits into from
Sep 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions pkg/servergroup/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@ import (
var (
// DefaultConfig is the Default base promxy configuration
DefaultConfig = Config{
AntiAffinity: time.Second * 10,
Scheme: "http",
RemoteReadPath: "api/v1/read",
Timeout: 0,
PreferMax: false,
AntiAffinity: time.Second * 10,
Scheme: "http",
RemoteReadPath: "api/v1/read",
Timeout: 0,
MaxIdleConns: 20000,
MaxIdleConnsPerHost: 1000,
IdleConnTimeout: 5 * time.Minute,
PreferMax: false,
HTTPConfig: HTTPClientConfig{
DialTimeout: time.Millisecond * 200, // Default dial timeout of 200ms
},
Expand Down Expand Up @@ -148,6 +151,15 @@ type Config struct {
// time does not include the time to read the response body.
Timeout time.Duration `yaml:"timeout,omitempty"`

// MaxIdleConns, servergroup maximum number of idle connections to keep open.
MaxIdleConns int `yaml:"max_idle_conns,omitempty"`

// MaxIdleConnsPerHost, servergroup maximum number of idle connections to keep open per host.
MaxIdleConnsPerHost int `yaml:"max_idle_conns_per_host,omitempty"`

// IdleConnTimeout, time wait to close a idle connections.
IdleConnTimeout time.Duration `yaml:"idle_conn_timeout,omitempty"`

// IgnoreError will hide all errors from this given servergroup effectively making
// the responses from this servergroup "not required" for the result.
// Note: this allows you to make the tradeoff between availability of queries and consistency of results
Expand Down
6 changes: 3 additions & 3 deletions pkg/servergroup/servergroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,13 +334,13 @@ func (s *ServerGroup) ApplyConfig(cfg *Config) error {
// It is applied on request. So we leave out any timings here.
var rt http.RoundTripper = &http.Transport{
Proxy: http.ProxyURL(cfg.HTTPConfig.HTTPConfig.ProxyURL.URL),
MaxIdleConns: 20000,
MaxIdleConnsPerHost: 1000, // see https://github.com/golang/go/issues/13801
MaxIdleConns: cfg.MaxIdleConns,
MaxIdleConnsPerHost: cfg.MaxIdleConnsPerHost, // see https://github.com/golang/go/issues/13801
DisableKeepAlives: false,
TLSClientConfig: tlsConfig,
// 5 minutes is typically above the maximum sane scrape interval. So we can
// use keepalive for all configurations.
IdleConnTimeout: 5 * time.Minute,
IdleConnTimeout: cfg.IdleConnTimeout,
DialContext: (&net.Dialer{Timeout: cfg.HTTPConfig.DialTimeout}).DialContext,
ResponseHeaderTimeout: cfg.Timeout,
}
Expand Down
Loading