mirror of
https://github.com/opf/openproject.git
synced 2026-06-14 03:30:14 +00:00
Change default DB pool settings in local dev setup
This commit is contained in:
@@ -38,7 +38,7 @@ development:
|
|||||||
adapter: postgresql
|
adapter: postgresql
|
||||||
encoding: unicode
|
encoding: unicode
|
||||||
database: openproject_development
|
database: openproject_development
|
||||||
pool: 5
|
pool: 100
|
||||||
username: openproject_development
|
username: openproject_development
|
||||||
password:
|
password:
|
||||||
|
|
||||||
|
|||||||
@@ -28,12 +28,34 @@
|
|||||||
# See COPYRIGHT and LICENSE files for more details.
|
# See COPYRIGHT and LICENSE files for more details.
|
||||||
#++
|
#++
|
||||||
|
|
||||||
config = Rails.env.production? && Rails.application.config.database_configuration[Rails.env]
|
if Rails.env.production?
|
||||||
pool_size = config && [OpenProject::Configuration.web_max_threads + 1, config["pool"].to_i].max
|
config = Rails.application.config.database_configuration[Rails.env]
|
||||||
|
pool_size = config && [OpenProject::Configuration.web_max_threads + 1, config["pool"].to_i].max
|
||||||
|
|
||||||
# make sure we have enough connections in the pool for each thread and then some
|
# make sure we have enough connections in the pool for each thread and then some
|
||||||
if pool_size && pool_size > ActiveRecord::Base.connection_pool.size
|
if pool_size && pool_size > ActiveRecord::Base.connection_pool.size
|
||||||
Rails.logger.info { "Increasing database pool size to #{pool_size} to match max threads" }
|
Rails.logger.info { "Increasing database pool size to #{pool_size} to match max threads" }
|
||||||
|
|
||||||
ActiveRecord::Base.establish_connection config.merge(pool: pool_size)
|
ActiveRecord::Base.establish_connection config.merge(pool: pool_size)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Per GoodJob's own recommendation (README "Database connections"), the pool must
|
||||||
|
# cover web threads, job threads, and GoodJob utility connections: 1 for the
|
||||||
|
# Notifier (LISTEN/NOTIFY) plus GoodJob::SharedExecutor::MAX_THREADS for cron/executor.
|
||||||
|
# The pool size is a ceiling — Rails creates connections lazily — so setting it
|
||||||
|
# to a large constant like 100 is the simplest safe choice (https://island94.org/2024/09/secret-to-rails-database-connection-pool-size).
|
||||||
|
if Rails.env.local?
|
||||||
|
utility_connections = 1 + GoodJob::SharedExecutor::MAX_THREADS
|
||||||
|
required_pool_size = OpenProject::Configuration.web_max_threads +
|
||||||
|
OpenProject::Configuration.good_job_max_threads +
|
||||||
|
utility_connections
|
||||||
|
|
||||||
|
if ActiveRecord::Base.connection_pool.size < required_pool_size
|
||||||
|
raise "DB pool (#{ActiveRecord::Base.connection_pool.size}) too small — need at least #{required_pool_size} " \
|
||||||
|
"(web_max_threads #{OpenProject::Configuration.web_max_threads} + " \
|
||||||
|
"good_job_max_threads #{OpenProject::Configuration.good_job_max_threads} + " \
|
||||||
|
"#{utility_connections} utility). " \
|
||||||
|
"Set pool: 100 in database.yml or ?pool=100 in DATABASE_URL."
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
+1
-1
@@ -42,7 +42,7 @@ x-op-backend: &backend
|
|||||||
OPENPROJECT_CACHE__MEMCACHE__SERVER: cache:11211
|
OPENPROJECT_CACHE__MEMCACHE__SERVER: cache:11211
|
||||||
OPENPROJECT_RAILS__CACHE__STORE: file_store
|
OPENPROJECT_RAILS__CACHE__STORE: file_store
|
||||||
OPENPROJECT_RAILS__RELATIVE__URL__ROOT: "${OPENPROJECT_RAILS__RELATIVE__URL__ROOT:-}"
|
OPENPROJECT_RAILS__RELATIVE__URL__ROOT: "${OPENPROJECT_RAILS__RELATIVE__URL__ROOT:-}"
|
||||||
DATABASE_URL: postgresql://${DB_USERNAME:-postgres}:${DB_PASSWORD:-postgres}@${DB_HOST:-db}:${DB_PORT:-5432}/${DB_DATABASE:-openproject}
|
DATABASE_URL: postgresql://${DB_USERNAME:-postgres}:${DB_PASSWORD:-postgres}@${DB_HOST:-db}:${DB_PORT:-5432}/${DB_DATABASE:-openproject}?pool=100
|
||||||
OPENPROJECT_EDITION: ${OPENPROJECT_EDITION:-standard}
|
OPENPROJECT_EDITION: ${OPENPROJECT_EDITION:-standard}
|
||||||
OPENPROJECT_WEB_MAX__THREADS: 1
|
OPENPROJECT_WEB_MAX__THREADS: 1
|
||||||
OPENPROJECT_WEB_MIN__THREADS: 1
|
OPENPROJECT_WEB_MIN__THREADS: 1
|
||||||
|
|||||||
Reference in New Issue
Block a user