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 12, 2024
1 parent 76dbb95 commit 5b43a41
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 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' => pick($foreman::db_pool, $foreman::foreman_service_puma_threads_max + 4),
}

file { '/etc/foreman/database.yml':
Expand Down
6 changes: 3 additions & 3 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@
#
# $db_root_cert:: Root cert used to verify SSL connection to postgres
#
# $db_pool:: Database 'production' size of connection pool. When running as a reverse proxy,
# the value of `$foreman_service_puma_threads_max` is used if it's higher than `$db_pool`.
# $db_pool:: Database 'production' size of connection pool. If the value is not set, it will be
# set by default to the amount of puma threads + 4 (for threads that are spawn by the system)
#
# $db_manage_rake:: if enabled, will run rake jobs, which depend on the database
#
Expand Down 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 5b43a41

Please sign in to comment.