Skip to content

Commit

Permalink
MySQL Performance when using GF_DATABASE_URL
Browse files Browse the repository at this point in the history
Set MaxIdleConn and MaxOpenConn when using the GF_DATABASE_URL configuration. Also added GF_DATABASE_DEBUG flag to print SQL statements and SQL execution times.
See grafana#9784 for the details.
  • Loading branch information
dfredell committed Nov 3, 2017
1 parent bf85735 commit 5fdfa3f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
3 changes: 3 additions & 0 deletions conf/defaults.ini
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ max_idle_conn = 2
# Max conn setting default is 0 (mean not set)
max_open_conn =

# Set to true to log the sql calls and execution times.
debug =

# For "postgres", use either "disable", "require" or "verify-full"
# For "mysql", use either "true", "false", or "skip-verify".
ssl_mode = disable
Expand Down
2 changes: 2 additions & 0 deletions conf/sample.ini
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@
# Max conn setting default is 0 (mean not set)
;max_open_conn =

# Set to true to log the sql calls and execution times.
debug =

#################################### Session ####################################
[session]
Expand Down
3 changes: 3 additions & 0 deletions docs/sources/installation/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ The maximum number of connections in the idle connection pool.
### max_open_conn
The maximum number of open connections to the database.

### debug
Set to `true` to log the sql calls and execution times.

<hr />

## [security]
Expand Down
16 changes: 10 additions & 6 deletions pkg/services/sqlstore/sqlstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,14 @@ func getEngine() (*xorm.Engine, error) {
} else {
engine.SetMaxOpenConns(DbCfg.MaxOpenConn)
engine.SetMaxIdleConns(DbCfg.MaxIdleConn)
engine.SetLogger(&xorm.DiscardLogger{})
// engine.SetLogger(NewXormLogger(log.LvlInfo, log.New("sqlstore.xorm")))
// engine.ShowSQL = true
// engine.ShowInfo = true
debugSql := setting.Cfg.Section("database").Key("debug").MustBool(false)
if !debugSql {
engine.SetLogger(&xorm.DiscardLogger{})
} else {
engine.SetLogger(NewXormLogger(log.LvlInfo, log.New("sqlstore.xorm")))
engine.ShowSQL(true)
engine.ShowExecTime(true)
}
}
return engine, nil
}
Expand Down Expand Up @@ -190,12 +194,12 @@ func LoadConfig() {
DbCfg.Host = sec.Key("host").String()
DbCfg.Name = sec.Key("name").String()
DbCfg.User = sec.Key("user").String()
DbCfg.MaxOpenConn = sec.Key("max_open_conn").MustInt(0)
DbCfg.MaxIdleConn = sec.Key("max_idle_conn").MustInt(0)
if len(DbCfg.Pwd) == 0 {
DbCfg.Pwd = sec.Key("password").String()
}
}
DbCfg.MaxOpenConn = sec.Key("max_open_conn").MustInt(0)
DbCfg.MaxIdleConn = sec.Key("max_idle_conn").MustInt(0)

if DbCfg.Type == "sqlite3" {
UseSQLite3 = true
Expand Down

0 comments on commit 5fdfa3f

Please sign in to comment.