Skip to content

Commit 2789aa8

Browse files
committed
make max open connections configurable for ch
1 parent 52cf655 commit 2789aa8

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

configs/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ type ClickhouseConfig struct {
8282
AsyncInsert bool `mapstructure:"asyncInsert"`
8383
MaxRowsPerInsert int `mapstructure:"maxRowsPerInsert"`
8484
ChainBasedConfig map[string]TableOverrideConfig `mapstructure:"chainBasedConfig"`
85+
MaxOpenConns int `mapstructure:"maxOpenConns"`
8586
}
8687

8788
type MemoryConfig struct {

internal/storage/clickhouse.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func connectDB(cfg *config.ClickhouseConfig) (clickhouse.Conn, error) {
8282
return nil, fmt.Errorf("invalid CLICKHOUSE_PORT: %d", port)
8383
}
8484

85-
conn, err := clickhouse.Open(&clickhouse.Options{
85+
options := &clickhouse.Options{
8686
Addr: []string{fmt.Sprintf("%s:%d", cfg.Host, port)},
8787
Protocol: clickhouse.Native,
8888
TLS: func() *tls.Config {
@@ -107,7 +107,12 @@ func connectDB(cfg *config.ClickhouseConfig) (clickhouse.Conn, error) {
107107
}
108108
return settings
109109
}(),
110-
})
110+
}
111+
if cfg.MaxOpenConns > 0 {
112+
options.MaxOpenConns = cfg.MaxOpenConns
113+
}
114+
115+
conn, err := clickhouse.Open(options)
111116
if err != nil {
112117
return nil, err
113118
}

0 commit comments

Comments
 (0)