From e4de7c2391885426ee60cb4e76a466128a38d7dd Mon Sep 17 00:00:00 2001 From: maru Date: Thu, 9 May 2024 14:22:20 -0400 Subject: [PATCH] Update database limiting code more --- db/db.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/db/db.go b/db/db.go index 3ab8c87..d927377 100644 --- a/db/db.go +++ b/db/db.go @@ -37,15 +37,16 @@ func Init(username, password, protocol, address, database string) error { if err != nil { return fmt.Errorf("failed to open database connection: %s", err) } - - if protocol == "unix" { - handle.SetMaxOpenConns(1000) - } else { - handle.SetMaxOpenConns(200) + + conns := 1024 + if protocol != "unix" { + conns = 256 } - handle.SetConnMaxIdleTime(time.Second * 30) - handle.SetConnMaxLifetime(time.Minute) + handle.SetMaxOpenConns(conns) + handle.SetMaxIdleConns(conns/4) + + handle.SetConnMaxIdleTime(time.Second * 10) tx, err := handle.Begin() if err != nil {