Commit dfc5f228 authored by Bob Van Landuyt's avatar Bob Van Landuyt Committed by Sean McGivern

Allow adding headroom to the connection pool

This allows setting the `DB_POOL_HEADROOM` env variable to add a
number of connections to the pool.

In normal situations, these connections should not be used, but it
allows us to investigate the problem without degrading the service.
parent 008df56c
...@@ -30,7 +30,7 @@ if Gitlab::Runtime.multi_threaded? ...@@ -30,7 +30,7 @@ if Gitlab::Runtime.multi_threaded?
Rails.application.config.database_configuration[Rails.env] Rails.application.config.database_configuration[Rails.env]
previous_db_pool_size = db_config['pool'] previous_db_pool_size = db_config['pool']
db_config['pool'] = [db_config['pool'].to_i, max_threads].max db_config['pool'] = [db_config['pool'].to_i, max_threads].max + ENV["DB_POOL_HEADROOM"].to_i
ActiveRecord::Base.establish_connection(db_config) ActiveRecord::Base.establish_connection(db_config)
......
...@@ -48,6 +48,21 @@ describe 'Database config initializer' do ...@@ -48,6 +48,21 @@ describe 'Database config initializer' do
expect { subject }.not_to change { Gitlab::Database.config['pool'] } expect { subject }.not_to change { Gitlab::Database.config['pool'] }
end end
end end
context "when specifying headroom through an ENV variable" do
let(:headroom) { 10 }
before do
stub_database_config(pool_size: 1)
stub_env("DB_POOL_HEADROOM", headroom)
end
it "adds headroom on top of the calculated size" do
expect { subject }.to change { Gitlab::Database.config['pool'] }
.from(1)
.to(max_threads + headroom)
end
end
end end
context "when using single-threaded runtime" do context "when using single-threaded runtime" do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment