From c60cc3525fab0f5509521a9ddf7d0b4bb1415201 Mon Sep 17 00:00:00 2001 From: Kailash Nadh Date: Wed, 11 Nov 2020 18:45:41 +0530 Subject: [PATCH 1/2] Remove alpha warning --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 9afe6ab..008f42a 100644 --- a/README.md +++ b/README.md @@ -7,8 +7,6 @@ listmonk is a standalone, self-hosted, newsletter and mailing list manager. It i [![listmonk-dashboard](https://user-images.githubusercontent.com/547147/89733057-87566580-da70-11ea-8160-855f6f046a55.png)](https://listmonk.app) Visit [listmonk.app](https://listmonk.app) -> listmonk is **alpha** software and may change and break. Use with caution. That said, it has been in active use at [zerodha.com](https://zerodha.com) where it has processed hundreds of campaigns and tens of millions of e-mails. - ## Installation ### Docker From ad8f290dad61d95b76299c387150590c2834d13a Mon Sep 17 00:00:00 2001 From: Karan Sharma Date: Tue, 17 Nov 2020 13:59:32 +0530 Subject: [PATCH 2/2] feat: Set default values for DB connection parameters - Configures `max_open` and `max_idle` in default configs to `25`. This changes the previous behaviour of connection pooling where both the values were unset (from default config) and causes unbounded connection limit and no connection reuse. - Configures `db.SetConnMaxLifetime` which sets the maximum time the connection can be reused in a pool. - Sets `max_conn_lifetime` in default config as `5 minutes`. Closes https://github.com/knadh/listmonk/issues/225 --- cmd/queries.go | 19 +++++++++++-------- config-demo.toml | 3 +++ config.toml.sample | 3 +++ 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/cmd/queries.go b/cmd/queries.go index 6e6e0c6..bf2edc4 100644 --- a/cmd/queries.go +++ b/cmd/queries.go @@ -4,6 +4,7 @@ import ( "context" "database/sql" "fmt" + "time" "github.com/jmoiron/sqlx" "github.com/lib/pq" @@ -84,14 +85,15 @@ type Queries struct { // dbConf contains database config required for connecting to a DB. type dbConf struct { - Host string `koanf:"host"` - Port int `koanf:"port"` - User string `koanf:"user"` - Password string `koanf:"password"` - DBName string `koanf:"database"` - SSLMode string `koanf:"ssl_mode"` - MaxOpen int `koanf:"max_open"` - MaxIdle int `koanf:"max_idle"` + Host string `koanf:"host"` + Port int `koanf:"port"` + User string `koanf:"user"` + Password string `koanf:"password"` + DBName string `koanf:"database"` + SSLMode string `koanf:"ssl_mode"` + MaxOpen int `koanf:"max_open"` + MaxIdle int `koanf:"max_idle"` + MaxLifetime time.Duration `koanf:"max_lifetime"` } // connectDB initializes a database connection. @@ -104,6 +106,7 @@ func connectDB(c dbConf) (*sqlx.DB, error) { } db.SetMaxOpenConns(c.MaxOpen) db.SetMaxIdleConns(c.MaxIdle) + db.SetConnMaxLifetime(c.MaxLifetime) return db, nil } diff --git a/config-demo.toml b/config-demo.toml index 03a0eb0..7aff549 100644 --- a/config-demo.toml +++ b/config-demo.toml @@ -10,3 +10,6 @@ password = "listmonk" database = "listmonk" ssl_mode = "disable" + max_open = 25 + max_idle = 25 + max_lifetime = "300s" diff --git a/config.toml.sample b/config.toml.sample index 7c0e3c6..7b09b77 100644 --- a/config.toml.sample +++ b/config.toml.sample @@ -17,3 +17,6 @@ password = "listmonk" database = "listmonk" ssl_mode = "disable" + max_open = 25 + max_idle = 25 + max_lifetime = "300s"