diff --git a/server/config/config.go b/server/config/config.go index 484aab379a..58ce21e02f 100644 --- a/server/config/config.go +++ b/server/config/config.go @@ -25,6 +25,8 @@ type MysqlConfig struct { TLSCA string `yaml:"tls_ca"` TLSServerName string `yaml:"tls_server_name"` TLSConfig string `yaml:"tls_config"` //tls=customValue in DSN + MaxOpenConns int `yaml:"max_open_conns"` + MaxIdleConns int `yaml:"max_idle_conns"` } // RedisConfig defines configs related to Redis @@ -121,6 +123,8 @@ func (man Manager) addConfigs() { "MySQL TLS server name") man.addConfigString("mysql.tls_config", "", "MySQL TLS config value. Use skip-verify, true, false or custom key.") + man.addConfigInt("mysql.max_open_conns", 50, "MySQL maximum open connection handles.") + man.addConfigInt("mysql.max_idle_conns", 50, "MySQL maximum idle connection handles.") // Redis man.addConfigString("redis.address", "localhost:6379", @@ -200,6 +204,8 @@ func (man Manager) LoadConfig() KolideConfig { TLSCA: man.getConfigString("mysql.tls_ca"), TLSServerName: man.getConfigString("mysql.tls_server_name"), TLSConfig: man.getConfigString("mysql.tls_config"), + MaxOpenConns: man.getConfigInt("mysql.max_open_conns"), + MaxIdleConns: man.getConfigInt("mysql.max_idle_conns"), }, Redis: RedisConfig{ Address: man.getConfigString("redis.address"), diff --git a/server/datastore/mysql/mysql.go b/server/datastore/mysql/mysql.go index 0291027261..98cef62065 100644 --- a/server/datastore/mysql/mysql.go +++ b/server/datastore/mysql/mysql.go @@ -73,6 +73,9 @@ func New(config config.MysqlConfig, c clock.Clock, opts ...DBOption) (*Datastore return nil, err } + db.SetMaxIdleConns(config.MaxIdleConns) + db.SetMaxOpenConns(config.MaxOpenConns) + var dbError error for attempt := 0; attempt < options.maxAttempts; attempt++ { dbError = db.Ping()