Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
e84d9fc6
Commit
e84d9fc6
authored
May 07, 2021
by
Thong Kuah
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Default pool size in Gitlab::Database.config
Fix max_threads for Puma with no cli_config
parent
1e536581
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
54 additions
and
15 deletions
+54
-15
config/initializers/database_config.rb
config/initializers/database_config.rb
+2
-12
lib/gitlab/database.rb
lib/gitlab/database.rb
+18
-1
lib/gitlab/runtime.rb
lib/gitlab/runtime.rb
+1
-1
spec/lib/gitlab/database_spec.rb
spec/lib/gitlab/database_spec.rb
+20
-0
spec/lib/gitlab/runtime_spec.rb
spec/lib/gitlab/runtime_spec.rb
+13
-1
No files found.
config/initializers/database_config.rb
View file @
e84d9fc6
...
...
@@ -20,25 +20,15 @@ Gitlab.ee do
end
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
headroom
=
(
ENV
[
"DB_POOL_HEADROOM"
].
presence
||
10
).
to_i
calculated_pool_size
=
Gitlab
::
Runtime
.
max_threads
+
headroom
db_config
=
Gitlab
::
Database
.
config
||
Rails
.
application
.
config
.
database_configuration
[
Rails
.
env
]
db_config
[
'pool'
]
=
calculated
_pool_size
db_config
[
'pool'
]
=
Gitlab
::
Database
.
default
_pool_size
ActiveRecord
::
Base
.
establish_connection
(
db_config
)
Gitlab
.
ee
do
if
Gitlab
::
Runtime
.
sidekiq?
&&
Gitlab
::
Geo
.
geo_database_configured?
Rails
.
configuration
.
geo_database
[
'pool'
]
=
calculated
_pool_size
Rails
.
configuration
.
geo_database
[
'pool'
]
=
Gitlab
::
Database
.
default
_pool_size
Geo
::
TrackingBase
.
establish_connection
(
Rails
.
configuration
.
geo_database
)
end
end
lib/gitlab/database.rb
View file @
e84d9fc6
...
...
@@ -43,10 +43,27 @@ module Gitlab
# It does not include the default public schema
EXTRA_SCHEMAS
=
[
DYNAMIC_PARTITIONS_SCHEMA
,
STATIC_PARTITIONS_SCHEMA
].
freeze
DEFAULT_POOL_HEADROOM
=
10
# 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
.
config
default_config_hash
=
ActiveRecord
::
Base
.
configurations
.
find_db_config
(
Rails
.
env
)
&
.
config
||
{}
default_config_hash
.
with_indifferent_access
default_config_hash
.
with_indifferent_access
.
tap
do
|
hash
|
# Match config/initializers/database_config.rb
hash
[
:pool
]
||=
default_pool_size
end
end
def
self
.
username
...
...
lib/gitlab/runtime.rb
View file @
e84d9fc6
...
...
@@ -87,7 +87,7 @@ module Gitlab
def
max_threads
threads
=
1
# main thread
if
puma?
if
puma?
&&
Puma
.
respond_to?
(
:cli_config
)
threads
+=
Puma
.
cli_config
.
options
[
:max_threads
]
elsif
sidekiq?
# An extra thread for the poller in Sidekiq Cron:
...
...
spec/lib/gitlab/database_spec.rb
View file @
e84d9fc6
...
...
@@ -15,10 +15,30 @@ RSpec.describe Gitlab::Database do
end
end
describe
'.default_pool_size'
do
before
do
allow
(
Gitlab
::
Runtime
).
to
receive
(
:max_threads
).
and_return
(
7
)
end
it
'returns the max thread size plus a fixed headroom of 10'
do
expect
(
described_class
.
default_pool_size
).
to
eq
(
17
)
end
it
'returns the max thread size plus a DB_POOL_HEADROOM if this env var is present'
do
stub_env
(
'DB_POOL_HEADROOM'
,
'7'
)
expect
(
described_class
.
default_pool_size
).
to
eq
(
14
)
end
end
describe
'.config'
do
it
'returns a HashWithIndifferentAccess'
do
expect
(
described_class
.
config
).
to
be_an_instance_of
(
HashWithIndifferentAccess
)
end
it
'returns a default pool size'
do
expect
(
described_class
.
config
).
to
include
(
pool:
described_class
.
default_pool_size
)
end
end
describe
'.adapter_name'
do
...
...
spec/lib/gitlab/runtime_spec.rb
View file @
e84d9fc6
...
...
@@ -42,7 +42,19 @@ RSpec.describe Gitlab::Runtime do
end
end
context
"puma"
do
# Puma has no cli_config method unless `puma/cli` is required
context
"puma without cli_config"
do
let
(
:puma_type
)
{
double
(
'::Puma'
)
}
before
do
stub_const
(
'::Puma'
,
puma_type
)
stub_env
(
'ACTION_CABLE_IN_APP'
,
'false'
)
end
it_behaves_like
"valid runtime"
,
:puma
,
1
end
context
"puma with cli_config"
do
let
(
:puma_type
)
{
double
(
'::Puma'
)
}
let
(
:max_workers
)
{
2
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment