Skip to content

Commit

Permalink
Fixes #33974 - Change the pool size to threads + 4
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ShimShtein committed May 9, 2024
1 parent 76dbb95 commit 6d1f3b7
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
2 changes: 1 addition & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion spec/classes/foreman_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 6d1f3b7

Please sign in to comment.