Skip to content
Open
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
2 changes: 2 additions & 0 deletions config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ max_error_reason_size: <byte_size>
connection_pool:
max_idle_conns: 100
max_idle_conns_per_host: 2
# Connection idle timeout must be < Clickhouse `keep_alive_timeout`.
idle_conn_timeout: 9

server:
<server_config> [optional]
Expand Down
5 changes: 5 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ var (
defaultConnectionPool = ConnectionPool{
MaxIdleConns: 100,
MaxIdleConnsPerHost: 2,
IdleConnTimeout: Duration(9 * time.Second),
}

defaultExecutionTime = Duration(120 * time.Second)
Expand Down Expand Up @@ -1062,6 +1063,10 @@ type ConnectionPool struct {
// Maximum number of idle connections between chproxy and particuler ClickHouse instance
MaxIdleConnsPerHost int `yaml:"max_idle_conns_per_host,omitempty"`

// Time that an idle connection is kept in the pool before being discarded.
// Should be set below the ClickHouse server's keep_alive_timeout.
IdleConnTimeout Duration `yaml:"idle_conn_timeout,omitempty"`

// Catches all undefined fields
XXX map[string]interface{} `yaml:",inline"`
}
Expand Down
2 changes: 2 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ var fullConfig = Config{
ConnectionPool: ConnectionPool{
MaxIdleConns: 100,
MaxIdleConnsPerHost: 2,
IdleConnTimeout: Duration(9 * time.Second),
},

Users: []User{
Expand Down Expand Up @@ -946,6 +947,7 @@ param_groups:
connection_pool:
max_idle_conns: 100
max_idle_conns_per_host: 2
idle_conn_timeout: 9s
`, redisPort)
tested := fullConfig.String()
if tested != expected {
Expand Down
4 changes: 4 additions & 0 deletions config/testdata/full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ connection_pool:
# Number of connections per ClickHouse host to keep open
# when they are not needed for clients.
max_idle_conns_per_host: 2
# Idle Timeout For Connections To Clickhouse. This value must be < the Clickhouse
# `keep_alive_timeout` to prevent graceful disconnection race-conditions that can
# result in Bad Gateway (unable to reach host errors)
idle_conn_timeout: 9s

# Settings for `chproxy` input interfaces.
server:
Expand Down
2 changes: 1 addition & 1 deletion proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func newReverseProxy(cfgCp *config.ConnectionPool) *reverseProxy {
ForceAttemptHTTP2: true,
MaxIdleConns: cfgCp.MaxIdleConns,
MaxIdleConnsPerHost: cfgCp.MaxIdleConnsPerHost,
IdleConnTimeout: 90 * time.Second,
IdleConnTimeout: time.Duration(cfgCp.IdleConnTimeout),
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
}
Expand Down