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 16, 2024
1 parent 76dbb95 commit c20c0ca
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
10 changes: 9 additions & 1 deletion manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,15 @@
'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.
# The number 4 is for 4 threads that are spawned internally during the execution:
# 1. Katello event daemon listener
# 2. Katello event monitor poller
# 3. Stomp listener (required by Katello)
# 4. Puma server listener thread
# This means for systems without Katello we can reduce the amount of the pool to puma_threads_max + 1
'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 c20c0ca

Please sign in to comment.