Merge pull request #8685 from blockscout/vb-fix-pool-size

Fix db pool size exceeds Postgres max connections
pull/8678/head
Victor Baranov 1 year ago committed by GitHub
commit 564a52c85d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      CHANGELOG.md
  2. 22
      apps/explorer/lib/explorer/application.ex
  3. 8
      config/runtime/dev.exs
  4. 20
      config/runtime/prod.exs

@ -6,6 +6,8 @@
### Fixes ### Fixes
- [#8685](https://github.com/blockscout/blockscout/pull/8685) - Fix db pool size exceeds Postgres max connections
### Chore ### Chore
<details> <details>

@ -47,9 +47,6 @@ defmodule Explorer.Application do
base_children = [ base_children = [
Explorer.Repo, Explorer.Repo,
Explorer.Repo.Replica1, Explorer.Repo.Replica1,
Explorer.Repo.Account,
Explorer.Repo.PolygonEdge,
Explorer.Repo.RSK,
Explorer.Vault, Explorer.Vault,
Supervisor.child_spec({SpandexDatadog.ApiServer, datadog_opts()}, id: SpandexDatadog.ApiServer), Supervisor.child_spec({SpandexDatadog.ApiServer, datadog_opts()}, id: SpandexDatadog.ApiServer),
Supervisor.child_spec({Task.Supervisor, name: Explorer.HistoryTaskSupervisor}, id: Explorer.HistoryTaskSupervisor), Supervisor.child_spec({Task.Supervisor, name: Explorer.HistoryTaskSupervisor}, id: Explorer.HistoryTaskSupervisor),
@ -93,6 +90,7 @@ defmodule Explorer.Application do
end end
defp configurable_children do defp configurable_children do
configurable_children_set =
[ [
configure(Explorer.ExchangeRates), configure(Explorer.ExchangeRates),
configure(Explorer.ExchangeRates.TokenExchangeRates), configure(Explorer.ExchangeRates.TokenExchangeRates),
@ -130,6 +128,24 @@ defmodule Explorer.Application do
configure(Explorer.Chain.Cache.RootstockLockedBTC) configure(Explorer.Chain.Cache.RootstockLockedBTC)
] ]
|> List.flatten() |> List.flatten()
repos_by_chain_type() ++ account_repo() ++ configurable_children_set
end
defp repos_by_chain_type do
if Mix.env() == :test do
[Explorer.Repo.PolygonEdge, Explorer.Repo.RSK]
else
[]
end
end
defp account_repo do
if System.get_env("ACCOUNT_DATABASE_URL") || Mix.env() == :test do
[Explorer.Repo.Account]
else
[]
end
end end
defp should_start?(process) do defp should_start?(process) do

@ -74,14 +74,18 @@ config :explorer, Explorer.Repo.PolygonEdge,
database: database, database: database,
hostname: hostname, hostname: hostname,
url: System.get_env("DATABASE_URL"), url: System.get_env("DATABASE_URL"),
pool_size: ConfigHelper.parse_integer_env_var("POLYGON_EDGE_POOL_SIZE", 10) # actually this repo is not started, and its pool size remains unused.
# separating repos for different CHAIN_TYPE is implemented only for the sake of keeping DB schema update relevant to the current chain type
pool_size: 1
# Configure Rootstock database # Configure Rootstock database
config :explorer, Explorer.Repo.RSK, config :explorer, Explorer.Repo.RSK,
database: database, database: database,
hostname: hostname, hostname: hostname,
url: System.get_env("DATABASE_URL"), url: System.get_env("DATABASE_URL"),
pool_size: pool_size # actually this repo is not started, and its pool size remains unused.
# separating repos for different CHAIN_TYPE is implemented only for the sake of keeping DB schema update relevant to the current chain type
pool_size: 1
variant = Variant.get() variant = Variant.get()

@ -27,10 +27,7 @@ config :block_scout_web, BlockScoutWeb.Endpoint,
### Explorer ### ### Explorer ###
################ ################
pool_size = pool_size = ConfigHelper.parse_integer_env_var("POOL_SIZE", 50)
if System.get_env("DATABASE_READ_ONLY_API_URL"),
do: ConfigHelper.parse_integer_env_var("POOL_SIZE", 50),
else: ConfigHelper.parse_integer_env_var("POOL_SIZE", 40)
# Configures the database # Configures the database
config :explorer, Explorer.Repo, config :explorer, Explorer.Repo,
@ -38,15 +35,10 @@ config :explorer, Explorer.Repo,
pool_size: pool_size, pool_size: pool_size,
ssl: ExplorerConfigHelper.ssl_enabled?() ssl: ExplorerConfigHelper.ssl_enabled?()
pool_size_api =
if System.get_env("DATABASE_READ_ONLY_API_URL"),
do: ConfigHelper.parse_integer_env_var("POOL_SIZE_API", 50),
else: ConfigHelper.parse_integer_env_var("POOL_SIZE_API", 10)
# Configures API the database # Configures API the database
config :explorer, Explorer.Repo.Replica1, config :explorer, Explorer.Repo.Replica1,
url: ExplorerConfigHelper.get_api_db_url(), url: ExplorerConfigHelper.get_api_db_url(),
pool_size: pool_size_api, pool_size: ConfigHelper.parse_integer_env_var("POOL_SIZE_API", 50),
ssl: ExplorerConfigHelper.ssl_enabled?() ssl: ExplorerConfigHelper.ssl_enabled?()
# Configures Account database # Configures Account database
@ -58,13 +50,17 @@ config :explorer, Explorer.Repo.Account,
# Configures PolygonEdge database # Configures PolygonEdge database
config :explorer, Explorer.Repo.PolygonEdge, config :explorer, Explorer.Repo.PolygonEdge,
url: System.get_env("DATABASE_URL"), url: System.get_env("DATABASE_URL"),
pool_size: ConfigHelper.parse_integer_env_var("POLYGON_EDGE_POOL_SIZE", 50), # actually this repo is not started, and its pool size remains unused.
# separating repos for different CHAIN_TYPE is implemented only for the sake of keeping DB schema update relevant to the current chain type
pool_size: 1,
ssl: ExplorerConfigHelper.ssl_enabled?() ssl: ExplorerConfigHelper.ssl_enabled?()
# Configures Rootstock database # Configures Rootstock database
config :explorer, Explorer.Repo.RSK, config :explorer, Explorer.Repo.RSK,
url: System.get_env("DATABASE_URL"), url: System.get_env("DATABASE_URL"),
pool_size: pool_size, # actually this repo is not started, and its pool size remains unused.
# separating repos for different CHAIN_TYPE is implemented only for the sake of keeping DB schema update relevant to the current chain type
pool_size: 1,
ssl: ExplorerConfigHelper.ssl_enabled?() ssl: ExplorerConfigHelper.ssl_enabled?()
variant = Variant.get() variant = Variant.get()

Loading…
Cancel
Save