From fe3708eaf495613cc6e2340b821795f25811d6ed Mon Sep 17 00:00:00 2001 From: bndw Date: Sat, 14 Feb 2026 09:44:55 -0800 Subject: fix: optimize SQLite connection pooling for single-writer architecture Remove misleading max_connections config option and properly configure SQLite connection pooling in the storage layer. Changes: - Set MaxOpenConns(1) for optimal SQLite performance - Set MaxIdleConns(1) to keep connection alive - Set ConnMaxLifetime(0) to never close connection - Remove max_connections and max_lifetime from DatabaseConfig - Update docs to clarify SQLite's single-writer architecture Rationale: SQLite is an embedded database with a single-writer lock. Multiple connections cause lock contention and reduce performance. WAL mode allows concurrent reads from the same connection, making connection pooling unnecessary and counterproductive. This change makes the configuration clearer and ensures optimal SQLite performance by using a single long-lived connection. --- internal/config/config.go | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) (limited to 'internal/config/config.go') diff --git a/internal/config/config.go b/internal/config/config.go index 87ca4eb..91e79f7 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -31,9 +31,9 @@ type ServerConfig struct { // DatabaseConfig holds database configuration. type DatabaseConfig struct { - Path string `yaml:"path"` - MaxConnections int `yaml:"max_connections"` - MaxLifetime time.Duration `yaml:"max_lifetime"` + Path string `yaml:"path"` + // Note: SQLite connection pooling is handled internally in the storage layer. + // SQLite works best with a single connection due to its single-writer architecture. } // AuthConfig holds authentication configuration. @@ -106,9 +106,7 @@ func Default() *Config { WriteTimeout: 30 * time.Second, }, Database: DatabaseConfig{ - Path: "relay.db", - MaxConnections: 10, - MaxLifetime: 1 * time.Hour, + Path: "relay.db", }, Auth: AuthConfig{ Enabled: false, @@ -239,12 +237,6 @@ func applyEnvOverrides(cfg *Config) { if val := os.Getenv("MUXSTR_DATABASE_PATH"); val != "" { cfg.Database.Path = val } - if val := os.Getenv("MUXSTR_DATABASE_MAX_CONNECTIONS"); val != "" { - var n int - if _, err := fmt.Sscanf(val, "%d", &n); err == nil { - cfg.Database.MaxConnections = n - } - } // Auth if val := os.Getenv("MUXSTR_AUTH_ENABLED"); val != "" { -- cgit v1.2.3