Allow users to set max MySQL connections and connection lifetime;
set a sane default for max connections if it's not present.
This commit is contained in:
Shivaram Lingamneni 2021-04-23 13:54:44 -04:00
parent a2b5548c8b
commit 5eed48c077
5 changed files with 23 additions and 0 deletions

View file

@ -17,6 +17,8 @@ type Config struct {
Password string
HistoryDatabase string `yaml:"history-database"`
Timeout time.Duration
MaxConns int `yaml:"max-conns"`
ConnMaxLifetime time.Duration `yaml:"conn-max-lifetime"`
// XXX these are copied from elsewhere in the config:
ExpireTime time.Duration

View file

@ -100,6 +100,14 @@ func (m *MySQL) Open() (err error) {
return err
}
if m.config.MaxConns != 0 {
m.db.SetMaxOpenConns(m.config.MaxConns)
m.db.SetMaxIdleConns(m.config.MaxConns)
}
if m.config.ConnMaxLifetime != 0 {
m.db.SetConnMaxLifetime(m.config.ConnMaxLifetime)
}
err = m.fixSchemas()
if err != nil {
return err