diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-09-09 18:09:24 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-09-09 18:09:24 +0300 |
commit | a3596259bcca06bf4adcdb391d0ea3110fe7deff (patch) | |
tree | deba3f6bbb1836133c4cafeb2ffe921d6bf3fed7 /lib/gitlab/database.rb | |
parent | 7ce86c261b3f910cf17b0b47a4200847578947df (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/database.rb')
-rw-r--r-- | lib/gitlab/database.rb | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/gitlab/database.rb b/lib/gitlab/database.rb index ce198061a49..f3f0d0305d3 100644 --- a/lib/gitlab/database.rb +++ b/lib/gitlab/database.rb @@ -6,6 +6,7 @@ module Gitlab MAIN_DATABASE_NAME = 'main' CI_DATABASE_NAME = 'ci' + DEFAULT_POOL_HEADROOM = 10 # This constant is used when renaming tables concurrently. # If you plan to rename a table using the `rename_table_safely` method, add your table here one milestone before the rename. @@ -62,6 +63,20 @@ module Gitlab DATABASES[PRIMARY_DATABASE_NAME] end + # We configure the database connection pool size automatically based on the + # configured concurrency. We also add some headroom, to make sure we don't + # run out of connections when more threads besides the 'user-facing' ones + # are running. + # + # Read more about this in + # doc/development/database/client_side_connection_pool.md + def self.default_pool_size + headroom = + (ENV["DB_POOL_HEADROOM"].presence || DEFAULT_POOL_HEADROOM).to_i + + Gitlab::Runtime.max_threads + headroom + end + def self.has_config?(database_name) Gitlab::Application.config.database_configuration[Rails.env].include?(database_name.to_s) end |