From f283dfc5cefa11e91fd0920ac3c37860f50a2449 Mon Sep 17 00:00:00 2001 From: tomleb Date: Mon, 3 Jul 2017 21:43:38 -0400 Subject: [PATCH] Reduce MaxOpenConn to increase performance (#1101) --- db/gorm.go | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/db/gorm.go b/db/gorm.go index a83ea3aee..00a4e3ec8 100644 --- a/db/gorm.go +++ b/db/gorm.go @@ -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)