Merge pull request #767 from tomleb/never_down_again
Activate the never_go_down again switch (fix slowdown issue)
Cette révision appartient à :
révision
075b51e43c
4 fichiers modifiés avec 19 ajouts et 5 suppressions
18
db/gorm.go
18
db/gorm.go
|
@ -9,6 +9,10 @@ import (
|
||||||
_ "github.com/jinzhu/gorm/dialects/sqlite" // Need for sqlite
|
_ "github.com/jinzhu/gorm/dialects/sqlite" // Need for sqlite
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
SqliteType = "sqlite3"
|
||||||
|
)
|
||||||
|
|
||||||
// Logger interface
|
// Logger interface
|
||||||
type Logger interface {
|
type Logger interface {
|
||||||
Print(v ...interface{})
|
Print(v ...interface{})
|
||||||
|
@ -32,15 +36,23 @@ func GormInit(conf *config.Config, logger Logger) (*gorm.DB, error) {
|
||||||
return nil, openErr
|
return nil, openErr
|
||||||
}
|
}
|
||||||
|
|
||||||
IsSqlite = conf.DBType == "sqlite"
|
IsSqlite = conf.DBType == SqliteType
|
||||||
|
|
||||||
connectionErr := db.DB().Ping()
|
connectionErr := db.DB().Ping()
|
||||||
if connectionErr != nil {
|
if connectionErr != nil {
|
||||||
log.CheckError(connectionErr)
|
log.CheckError(connectionErr)
|
||||||
return nil, connectionErr
|
return nil, connectionErr
|
||||||
}
|
}
|
||||||
db.DB().SetMaxIdleConns(10)
|
|
||||||
db.DB().SetMaxOpenConns(100)
|
// Negative MaxIdleConns means don't retain any idle connection
|
||||||
|
maxIdleConns := -1
|
||||||
|
if IsSqlite {
|
||||||
|
// sqlite doesn't like having a negative maxIdleConns
|
||||||
|
maxIdleConns = 10
|
||||||
|
}
|
||||||
|
|
||||||
|
db.DB().SetMaxIdleConns(maxIdleConns)
|
||||||
|
db.DB().SetMaxOpenConns(400)
|
||||||
|
|
||||||
if config.Environment == "DEVELOPMENT" {
|
if config.Environment == "DEVELOPMENT" {
|
||||||
db.LogMode(true)
|
db.LogMode(true)
|
||||||
|
|
|
@ -26,7 +26,7 @@ func (logger *errorLogger) Print(values ...interface{}) {
|
||||||
|
|
||||||
func TestGormInitSqlite(t *testing.T) {
|
func TestGormInitSqlite(t *testing.T) {
|
||||||
conf := config.New()
|
conf := config.New()
|
||||||
conf.DBType = "sqlite3"
|
conf.DBType = SqliteType
|
||||||
conf.DBParams = ":memory:?cache=shared&mode=memory"
|
conf.DBParams = ":memory:?cache=shared&mode=memory"
|
||||||
conf.DBLogMode = "detailed"
|
conf.DBLogMode = "detailed"
|
||||||
|
|
||||||
|
|
|
@ -62,7 +62,7 @@ max_pool = 4
|
||||||
|
|
||||||
# - Life time -
|
# - Life time -
|
||||||
|
|
||||||
child_life_time = 300
|
child_life_time = {{ child_life_time }}
|
||||||
# Pool exits after being idle for this many seconds
|
# Pool exits after being idle for this many seconds
|
||||||
child_max_connections = 0
|
child_max_connections = 0
|
||||||
# Pool exits after receiving that many connections
|
# Pool exits after receiving that many connections
|
||||||
|
|
|
@ -6,3 +6,5 @@ memqcache_total_size_byte: 10737418240
|
||||||
memqcache_maxcache_byte: 131072000
|
memqcache_maxcache_byte: 131072000
|
||||||
# Has to be bigger or equal to maxcache_byte
|
# Has to be bigger or equal to maxcache_byte
|
||||||
memqcache_cache_block_size_byte: 131072000
|
memqcache_cache_block_size_byte: 131072000
|
||||||
|
# 20 seconds idle max (application shouldn't even make idle connections)
|
||||||
|
child_life_time: 20
|
||||||
|
|
Référencer dans un nouveau ticket