From 6d1f3b776f9774da5b6a7704dcbddb95f5b1a6b6 Mon Sep 17 00:00:00 2001 From: Shimon Shtein Date: Wed, 24 Apr 2024 14:30:31 +0300 Subject: [PATCH] Fixes #33974 - Change the pool size to threads + 4 According to an investigation described in https://community.theforeman.org/t/rails-connection-pool-size-optimizations/36675 foreman process spawns 4 additional threads that consume DB connection during the startup. Hence the amount of acctive DB connections should be the amount of puma threads + 4 additional threads. --- manifests/config.pp | 4 +++- manifests/init.pp | 2 +- spec/classes/foreman_spec.rb | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/manifests/config.pp b/manifests/config.pp index fb9953d22..7fa5b3d75 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -68,7 +68,9 @@ 'database' => $foreman::db_database, 'username' => $foreman::db_username, 'password' => $foreman::db_password, - 'db_pool' => max($foreman::db_pool, $foreman::foreman_service_puma_threads_max), + # Set the pool size to at least the amount of puma threads + 4 threads that are spawned automatically by the process. + # db_pool is optional, and undef means "use default" and the second part of the max statement will be set + 'db_pool' => max(pick($foreman::db_pool, 0), $foreman::foreman_service_puma_threads_max + 4), } file { '/etc/foreman/database.yml': diff --git a/manifests/init.pp b/manifests/init.pp index 08d901d38..a87220b4d 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -226,7 +226,7 @@ String[1] $db_password = $foreman::params::db_password, Optional[String[1]] $db_sslmode = undef, Optional[String[1]] $db_root_cert = undef, - Integer[0] $db_pool = 5, + Optional[Integer[0]] $db_pool = undef, Boolean $db_manage_rake = true, Stdlib::Port $server_port = 80, Stdlib::Port $server_ssl_port = 443, diff --git a/spec/classes/foreman_spec.rb b/spec/classes/foreman_spec.rb index df552d354..35e4a2d65 100644 --- a/spec/classes/foreman_spec.rb +++ b/spec/classes/foreman_spec.rb @@ -199,7 +199,7 @@ db_username: 'foreman', db_password: 'secret', db_sslmode: 'prefer', - db_pool: 5, + db_pool: 9, db_manage_rake: true, server_port: 80, server_ssl_port: 443,