diff --git a/backend/src/app/db.clj b/backend/src/app/db.clj index 23b5ddad7a..bfce3b2274 100644 --- a/backend/src/app/db.clj +++ b/backend/src/app/db.clj @@ -70,6 +70,7 @@ (def defaults {::name :main + ::min-size 0 ::max-size 60 ::connection-timeout 30000 ::validation-timeout 10000 @@ -92,8 +93,7 @@ :read-only read-only :credentials (and (contains? cfg ::username) (contains? cfg ::password)) - :min-size (or (::min-size cfg) - (::max-size cfg)) + :min-size (::min-size cfg) :max-size (::max-size cfg)) (create-pool cfg)))) @@ -117,9 +117,7 @@ [{:keys [::uri] :as cfg}] ;; (app.common.pprint/pprint cfg) - (let [config (HikariConfig.) - max-size (::max-size cfg) - min-size (or (::min-size cfg) max-size)] + (let [config (HikariConfig.)] (doto config (.setJdbcUrl (str "jdbc:" uri)) (.setPoolName (d/name (::name cfg))) @@ -129,8 +127,8 @@ (.setValidationTimeout (::validation-timeout cfg)) (.setIdleTimeout (::idle-timeout cfg)) (.setMaxLifetime (::max-lifetime cfg)) - (.setMinimumIdle min-size) - (.setMaximumPoolSize max-size) + (.setMinimumIdle (::min-size cfg)) + (.setMaximumPoolSize (::max-size cfg)) (.setConnectionInitSql initsql) (.setInitializationFailTimeout -1)) diff --git a/docs/technical-guide/configuration.md b/docs/technical-guide/configuration.md index c296d2bdeb..6e24a85591 100644 --- a/docs/technical-guide/configuration.md +++ b/docs/technical-guide/configuration.md @@ -757,6 +757,25 @@ POSTGRES_USER: penpot POSTGRES_PASSWORD: penpot ``` +#### Connection pool + +The backend keeps a pool of database connections. Its size can be tuned with: + +```bash +# Backend +PENPOT_DATABASE_MIN_POOL_SIZE: 0 +PENPOT_DATABASE_MAX_POOL_SIZE: 60 +``` + +The values above are the defaults. The pool keeps at least `MIN_POOL_SIZE` idle +connections open and never opens more than `MAX_POOL_SIZE`, growing only under load +and closing idle connections after two minutes. A minimum larger than the maximum is +capped at the maximum. + +If the PostgreSQL server is shared with other applications, make sure +`PENPOT_DATABASE_MAX_POOL_SIZE` plus the connections used by everything else stays below +the server's `max_connections` (100 by default). + ### Storage Storage refers to storing the user uploaded different objects in Penpot (assets, file data,...).