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

[ffresty] maxIdleConnsPerHost Setting #154

Merged
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
10 changes: 8 additions & 2 deletions pkg/ffresty/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ const (
defaultRequestTimeout = "30s"
defaultHTTPIdleTimeout = "475ms" // Node.js default keepAliveTimeout is 5 seconds, so we have to set a base below this
defaultHTTPMaxIdleConns = 100 // match Go's default
defaultHTTPMaxConnsPerHost = 0
defaultHTTPMaxConnsPerHost = 0 // unlimited
defaultHTTPMaxIdleConnsPerHost = 100 // avoid Go's conservative default of 2, we'd rather it be the same as the maxIdleConns so a single host can use all the connections
defaultHTTPConnectionTimeout = "30s"
defaultHTTPTLSHandshakeTimeout = "10s" // match Go's default
defaultHTTPExpectContinueTimeout = "1s" // match Go's default
Expand Down Expand Up @@ -75,8 +76,11 @@ const (
// HTTPThrottleBurst The maximum number of requests that can be made in a short period of time before the RPS throttling kicks in.
HTTPThrottleBurst = "throttle.burst"

// HTTPMaxConnsPerHost the max number of concurrent connections
// HTTPMaxConnsPerHost the max number of concurrent connections per host
HTTPMaxConnsPerHost = "maxConnsPerHost"
// HTTPMaxIdleConnsPerHost the max number of idle connections per host
HTTPMaxIdleConnsPerHost = "maxIdleConnsPerHost"

// HTTPConnectionTimeout the connection timeout for new connections
HTTPConnectionTimeout = "connectionTimeout"
// HTTPTLSHandshakeTimeout the TLS handshake connection timeout
Expand Down Expand Up @@ -107,6 +111,7 @@ func InitConfig(conf config.Section) {
conf.AddKnownKey(HTTPIdleTimeout, defaultHTTPIdleTimeout)
conf.AddKnownKey(HTTPMaxIdleConns, defaultHTTPMaxIdleConns)
conf.AddKnownKey(HTTPMaxConnsPerHost, defaultHTTPMaxConnsPerHost)
conf.AddKnownKey(HTTPMaxIdleConnsPerHost, defaultHTTPMaxIdleConnsPerHost)
conf.AddKnownKey(HTTPConnectionTimeout, defaultHTTPConnectionTimeout)
conf.AddKnownKey(HTTPTLSHandshakeTimeout, defaultHTTPTLSHandshakeTimeout)
conf.AddKnownKey(HTTPExpectContinueTimeout, defaultHTTPExpectContinueTimeout)
Expand Down Expand Up @@ -136,6 +141,7 @@ func GenerateConfig(ctx context.Context, conf config.Section) (*Config, error) {
HTTPIdleConnTimeout: fftypes.FFDuration(conf.GetDuration(HTTPIdleTimeout)),
HTTPMaxIdleConns: conf.GetInt(HTTPMaxIdleConns),
HTTPMaxConnsPerHost: conf.GetInt(HTTPMaxConnsPerHost),
HTTPMaxIdleConnsPerHost: conf.GetInt(HTTPMaxIdleConnsPerHost),
HTTPConnectionTimeout: fftypes.FFDuration(conf.GetDuration(HTTPConnectionTimeout)),
HTTPTLSHandshakeTimeout: fftypes.FFDuration(conf.GetDuration(HTTPTLSHandshakeTimeout)),
HTTPExpectContinueTimeout: fftypes.FFDuration(conf.GetDuration(HTTPExpectContinueTimeout)),
Expand Down
2 changes: 2 additions & 0 deletions pkg/ffresty/ffresty.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ type HTTPConfig struct {
RetryErrorStatusCodeRegex string `ffstruct:"RESTConfig" json:"retryErrorStatusCodeRegex,omitempty"`
HTTPMaxIdleConns int `ffstruct:"RESTConfig" json:"maxIdleConns,omitempty"`
HTTPMaxConnsPerHost int `ffstruct:"RESTConfig" json:"maxConnsPerHost,omitempty"`
HTTPMaxIdleConnsPerHost int `ffstruct:"RESTConfig" json:"maxIdleConnsPerHost,omitempty"`
HTTPPassthroughHeadersEnabled bool `ffstruct:"RESTConfig" json:"httpPassthroughHeadersEnabled,omitempty"`
HTTPHeaders fftypes.JSONObject `ffstruct:"RESTConfig" json:"headers,omitempty"`
HTTPTLSHandshakeTimeout fftypes.FFDuration `ffstruct:"RESTConfig" json:"tlsHandshakeTimeout,omitempty"`
Expand Down Expand Up @@ -210,6 +211,7 @@ func NewWithConfig(ctx context.Context, ffrestyConfig Config) (client *resty.Cli
ForceAttemptHTTP2: true,
MaxIdleConns: ffrestyConfig.HTTPMaxIdleConns,
MaxConnsPerHost: ffrestyConfig.HTTPMaxConnsPerHost,
MaxIdleConnsPerHost: ffrestyConfig.HTTPMaxConnsPerHost,
IdleConnTimeout: time.Duration(ffrestyConfig.HTTPIdleConnTimeout),
TLSHandshakeTimeout: time.Duration(ffrestyConfig.HTTPTLSHandshakeTimeout),
ExpectContinueTimeout: time.Duration(ffrestyConfig.HTTPExpectContinueTimeout),
Expand Down
1 change: 1 addition & 0 deletions pkg/i18n/en_base_config_descriptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ var (
ConfigGlobalThrottleBurst = ffc("config.global.throttle.burst", "The maximum number of requests that can be made in a short period of time before the throttling kicks in.", IntType)
ConfigGlobalMaxIdleConns = ffc("config.global.maxIdleConns", "The max number of idle connections to hold pooled", IntType)
ConfigGlobalMaxConnsPerHost = ffc("config.global.maxConnsPerHost", "The max number of connections, per unique hostname. Zero means no limit", IntType)
ConfigGlobalMaxIdleConnsPerHost = ffc("config.global.maxIdleConnsPerHost", "The max number of idle connections, per unique hostname. Zero means net/http uses the default of only 2.", IntType)
ConfigGlobalMethod = ffc("config.global.method", "The HTTP method to use when making requests to the Address Resolver", StringType)
ConfigGlobalAuthType = ffc("config.global.auth.type", "The auth plugin to use for server side authentication of requests", StringType)
ConfigGlobalPassthroughHeadersEnabled = ffc("config.global.passthroughHeadersEnabled", "Enable passing through the set of allowed HTTP request headers", BooleanType)
Expand Down
1 change: 1 addition & 0 deletions pkg/i18n/en_base_field_descriptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ var (
RESTConfigThrottleRequestsPerSecond = ffm("RESTConfig.requestsPerSecond", "Requests per second")
RESTConfigThrottleBurst = ffm("RESTConfig.burst", "Burst")
RESTConfigMaxConnsPerHost = ffm("RESTConfig.maxConnsPerHost", "Maximum connections per host")
RESTConfigMaxIdleConnsPerHost = ffm("RESTConfig.maxIdleConnsPerHost", "Maximum idle connections per host")
RESTConfigMaxIdleConns = ffm("RESTConfig.maxIdleConns", "Maximum idle connections to leave in the connection pool")
RESTConfigMaxIdleTimeout = ffm("RESTConfig.maxIdleTimeout", "Maximum time to leave idle connections in the connection pool")
RESTConfigProxyURL = ffm("RESTConfig.proxyURL", "URL of a proxy server to use for connections")
Expand Down
Loading