From 4ee4cd2da11bc0199ee99a40527e758d394dbc9c Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Wed, 1 Feb 2023 11:55:34 +0100 Subject: [PATCH] [chore/performance] use only 1 sqlite db connection regardless of multiplier (#1408) --- docs/configuration/database.md | 4 ++++ example/config.yaml | 4 ++++ internal/db/bundb/bundb.go | 6 +++--- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/docs/configuration/database.md b/docs/configuration/database.md index 758a01439..047b8c198 100644 --- a/docs/configuration/database.md +++ b/docs/configuration/database.md @@ -128,6 +128,10 @@ db-tls-ca-cert: "" # # If you set the multiplier to less than 1, only one open connection will be used regardless of cpu count. # +# PLEASE NOTE!!: This setting currently only applies for Postgres. SQLite will always use 1 connection regardless +# of what is set here. This behavior will change in future when we implement better SQLITE_BUSY handling. +# See https://github.com/superseriousbusiness/gotosocial/issues/1407 for more details. +# # Examples: [16, 8, 10, 2] # Default: 8 db-max-open-conns-multiplier: 8 diff --git a/example/config.yaml b/example/config.yaml index f7d7c7884..b411da4db 100644 --- a/example/config.yaml +++ b/example/config.yaml @@ -184,6 +184,10 @@ db-tls-ca-cert: "" # # If you set the multiplier to less than 1, only one open connection will be used regardless of cpu count. # +# PLEASE NOTE!!: This setting currently only applies for Postgres. SQLite will always use 1 connection regardless +# of what is set here. This behavior will change in future when we implement better SQLITE_BUSY handling. +# See https://github.com/superseriousbusiness/gotosocial/issues/1407 for more details. +# # Examples: [16, 8, 10, 2] # Default: 8 db-max-open-conns-multiplier: 8 diff --git a/internal/db/bundb/bundb.go b/internal/db/bundb/bundb.go index 6587ab8ad..0ab1d1b83 100644 --- a/internal/db/bundb/bundb.go +++ b/internal/db/bundb/bundb.go @@ -304,9 +304,9 @@ func sqliteConn(ctx context.Context) (*DBConn, error) { // Tune db connections for sqlite, see: // - https://bun.uptrace.dev/guide/running-bun-in-production.html#database-sql // - https://www.alexedwards.net/blog/configuring-sqldb - sqldb.SetMaxOpenConns(maxOpenConns()) // x number of conns per cpu - sqldb.SetMaxIdleConns(1) // only keep max 1 idle connection around - sqldb.SetConnMaxLifetime(0) // don't kill connections due to age + sqldb.SetMaxOpenConns(1) // only 1 connection regardless of multiplier, see https://github.com/superseriousbusiness/gotosocial/issues/1407 + sqldb.SetMaxIdleConns(1) // only keep max 1 idle connection around + sqldb.SetConnMaxLifetime(0) // don't kill connections due to age // Wrap Bun database conn in our own wrapper conn := WrapDBConn(bun.NewDB(sqldb, sqlitedialect.New()))