Skip to content

Commit

Permalink
Reduce MaxOpenConn to increase performance (#1101)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomleb authored and ewhal committed Jul 4, 2017
1 parent 2319b67 commit f283dfc
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions db/gorm.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,13 @@ func GormInit(conf *config.Config, logger Logger) (*gorm.DB, error) {
return nil, connectionErr
}

// 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)
db.DB().SetMaxIdleConns(1)
// This should be about the number of cores the machine has (and should
// be lower than the max_connection specified by postgresql.conf)
// Since we have two applications running, this should really be
// number of cores / 2
// TODO Make configurable
db.DB().SetMaxOpenConns(4)

if config.Conf.Environment == "DEVELOPMENT" {
db.LogMode(true)
Expand Down

0 comments on commit f283dfc

Please sign in to comment.