diff --git a/config/config.example.yml b/config/config.example.yml index d2346719..8a343867 100644 --- a/config/config.example.yml +++ b/config/config.example.yml @@ -15,6 +15,29 @@ db: port: 5432 dbname: invidious + ## + ## Granular pooling behavior controls + ## The following is entirely optional. + ## + + ## Initial amount of connections in the pool + #initial_pool_size: + + ## Maximum amount of connections in the pool. 0 is unlimited. + #max_pool_size: 0 + + ## Amount of connections when idle + #max_idle_pool_size: 1 + + ## Amount of seconds to wait if the connection pool is full, and a connection is unavailable. + #checkout_timeout: 5 + + ## Amount of retries when a connection is either lost or can't be established. + #retry_attempts: 1 + + ## Amount of seconds between each retry + #retry_delay: 1 + ## ## Database configuration using a single URI. This is an ## alternative to the 'db' parameter above. If both forms diff --git a/src/invidious/helpers/helpers.cr b/src/invidious/helpers/helpers.cr index fb33df1c..22aebca9 100644 --- a/src/invidious/helpers/helpers.cr +++ b/src/invidious/helpers/helpers.cr @@ -188,6 +188,16 @@ class Config host: db.host, port: db.port, path: db.dbname, + + # Pooling config + query: URI::Params.build do |pool_controls| + pool_controls.add "initial_pool_size", db.initial_pool_size.to_s + pool_controls.add "max_pool_size", db.max_pool_size.to_s + pool_controls.add "max_idle_pool_size", db.max_idle_pool_size.to_s + pool_controls.add "checkout_timeout", db.checkout_timeout.to_s + pool_controls.add "retry_attempts", db.retry_attempts.to_s + pool_controls.add "retry_delay", db.retry_delay.to_s + end ) else puts "Config : Either database_url or db.* is required" @@ -207,6 +217,14 @@ struct DBConfig property host : String property port : Int32 property dbname : String + + # https://crystal-lang.org/reference/database/connection_pool.html#configuration + property initial_pool_size : Int32 = 1 + property max_pool_size : Int32 = 0 + property max_idle_pool_size : Int32 = 1 + property checkout_timeout : Int32 = 5 + property retry_attempts : Int32 = 1 + property retry_delay : Int32 = 1 end def login_req(f_req)