From 18e6460d93c55685a4fb9be9b3183e18fe286466 Mon Sep 17 00:00:00 2001 From: Jeroen Date: Thu, 26 Oct 2023 16:35:30 +0200 Subject: [PATCH] Added config for distribution support --- core/config/runtime.exs | 10 ++++++++++ core/lib/core/application.ex | 12 ++++++++++++ core/mix.exs | 1 + core/mix.lock | 1 + core/rel/env.bat.eex | 8 ++++++++ core/rel/env.sh.eex | 24 ++++++++++++++++++++++++ core/rel/remote.vm.args.eex | 8 ++++++++ core/rel/vm.args.eex | 9 +++++++++ 8 files changed, 73 insertions(+) create mode 100644 core/rel/env.bat.eex create mode 100644 core/rel/env.sh.eex create mode 100644 core/rel/remote.vm.args.eex create mode 100644 core/rel/vm.args.eex diff --git a/core/config/runtime.exs b/core/config/runtime.exs index 12aa9a0836..3d52c7307e 100644 --- a/core/config/runtime.exs +++ b/core/config/runtime.exs @@ -135,4 +135,14 @@ if config_env() == :prod do # The public URL must point to the root's (bucket) publicly accessible URL. # It should have a policy that allows anonymous users to read all files. public_url: System.get_env("FELDSPAR_S3_PUBLIC_URL") + + config :core, + :dist_hosts, + "DIST_HOSTS" + |> System.get_env("") + |> String.split(",") + |> Enum.map(&String.trim/1) + |> Enum.reject(&(&1 == "")) + |> Enum.map(&"core@#{&1}") + |> Enum.map(&String.to_atom/1) end diff --git a/core/lib/core/application.ex b/core/lib/core/application.ex index 467160c8ee..b537ea4ce7 100644 --- a/core/lib/core/application.ex +++ b/core/lib/core/application.ex @@ -6,7 +6,15 @@ defmodule Core.Application do use Application def start(_type, _args) do + topologies = [ + example: [ + strategy: Cluster.Strategy.Epmd, + config: [hosts: dist_hosts()] + ] + ] + children = [ + {Cluster.Supervisor, [topologies, [name: MyApp.ClusterSupervisor]]}, Core.Repo, CoreWeb.Telemetry, {Phoenix.PubSub, name: Core.PubSub}, @@ -31,4 +39,8 @@ defmodule Core.Application do defp rate_config do Application.fetch_env!(:core, :rate) end + + defp dist_hosts do + Application.get_env(:core, :dist_hosts, []) + end end diff --git a/core/mix.exs b/core/mix.exs index 7107797b81..62327bdce9 100644 --- a/core/mix.exs +++ b/core/mix.exs @@ -100,6 +100,7 @@ defmodule Core.MixProject do {:statistics, "~> 0.6.2"}, {:csv, "~> 2.4"}, {:sentry, "~> 8.0"}, + {:libcluster, "~> 3.3"}, # i18n {:ex_cldr, "~> 2.25"}, {:ex_cldr_numbers, "~> 2.23"}, diff --git a/core/mix.lock b/core/mix.lock index 9690203340..04465695a5 100644 --- a/core/mix.lock +++ b/core/mix.lock @@ -61,6 +61,7 @@ "joken": {:hex, :joken, "2.6.0", "b9dd9b6d52e3e6fcb6c65e151ad38bf4bc286382b5b6f97079c47ade6b1bcc6a", [:mix], [{:jose, "~> 1.11.5", [hex: :jose, repo: "hexpm", optional: false]}], "hexpm", "5a95b05a71cd0b54abd35378aeb1d487a23a52c324fa7efdffc512b655b5aaa7"}, "jose": {:hex, :jose, "1.11.5", "3bc2d75ffa5e2c941ca93e5696b54978323191988eb8d225c2e663ddfefd515e", [:mix, :rebar3], [], "hexpm", "dcd3b215bafe02ea7c5b23dafd3eb8062a5cd8f2d904fd9caa323d37034ab384"}, "kadabra": {:hex, :kadabra, "0.6.0", "8d8de886802f38d86d2c250eb9416e3208b5e4b78ce8409b40b4d57f21d21fc9", [:mix], [{:certifi, "~> 2.5", [hex: :certifi, repo: "hexpm", optional: false]}, {:hpack, "~> 0.2.3", [hex: :hpack_erl, repo: "hexpm", optional: false]}], "hexpm", "0cdaf72fc6205cba62da9e49ee6b24b7c50adb6d9f8b0e92b4b1847959371403"}, + "libcluster": {:hex, :libcluster, "3.3.3", "a4f17721a19004cfc4467268e17cff8b1f951befe428975dd4f6f7b84d927fe0", [:mix], [{:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "7c0a2275a0bb83c07acd17dab3c3bfb4897b145106750eeccc62d302e3bdfee5"}, "logger_json": {:hex, :logger_json, "4.3.0", "41aaaab2c2e1c071bfddbcc5a3f567884fdf312d222c7f1a7e3de6ab667774f7", [:mix], [{:ecto, "~> 2.1 or ~> 3.0", [hex: :ecto, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: true]}], "hexpm", "001bbc34d7c451cfeed298c8384cb3aab10b364db2eb095c466c7a1a28bee6e0"}, "luhn": {:hex, :luhn, "0.3.3", "5aa0c6a32c2db4b9db9f9b883ba8301c1ae169d57199b9e6cb1ba2707bc51d96", [:mix], [], "hexpm", "3e823a913a25aab51352c727f135278d22954874d5f0835be81ed4fec3daf78d"}, "mail": {:hex, :mail, "0.2.3", "2c6bb5f8a5f74845fa50ecd0fb45ea16b164026f285f45104f1c4c078cd616d4", [:mix], [], "hexpm", "932b398fa9c69fdf290d7ff63175826e0f1e24414d5b0763bb00a2acfc6c6bf5"}, diff --git a/core/rel/env.bat.eex b/core/rel/env.bat.eex new file mode 100644 index 0000000000..0d82afd907 --- /dev/null +++ b/core/rel/env.bat.eex @@ -0,0 +1,8 @@ +@echo off +rem Set the release to load code on demand (interactive) instead of preloading (embedded). +rem set RELEASE_MODE=interactive + +rem Set the release to work across nodes. +rem RELEASE_DISTRIBUTION must be "sname" (local), "name" (distributed) or "none". +rem set RELEASE_DISTRIBUTION=name +rem set RELEASE_NODE=<%= @release.name %> diff --git a/core/rel/env.sh.eex b/core/rel/env.sh.eex new file mode 100644 index 0000000000..8b31075179 --- /dev/null +++ b/core/rel/env.sh.eex @@ -0,0 +1,24 @@ +#!/bin/sh + +# # Sets and enables heart (recommended only in daemon mode) +# case $RELEASE_COMMAND in +# daemon*) +# HEART_COMMAND="$RELEASE_ROOT/bin/$RELEASE_NAME $RELEASE_COMMAND" +# export HEART_COMMAND +# export ELIXIR_ERL_OPTIONS="-heart" +# ;; +# *) +# ;; +# esac + +# # Set the release to load code on demand (interactive) instead of preloading (embedded). +# export RELEASE_MODE=interactive + +# # Set the release to work across nodes. +# # RELEASE_DISTRIBUTION must be "sname" (local), "name" (distributed) or "none". +# export RELEASE_DISTRIBUTION=name +# export RELEASE_NODE=<%= @release.name %> + +if [ ! -z "${DIST_TLS_CONF}" ]; then + export ELIXIR_ERL_OPTIONS="-proto_dist inet_tls -ssl_dist_optfile ${DIST_TLS_CONF}" +fi \ No newline at end of file diff --git a/core/rel/remote.vm.args.eex b/core/rel/remote.vm.args.eex new file mode 100644 index 0000000000..983397a703 --- /dev/null +++ b/core/rel/remote.vm.args.eex @@ -0,0 +1,8 @@ +## Customize flags given to the VM: https://www.erlang.org/doc/man/erl.html +## -mode/-name/-sname/-setcookie are configured via env vars, do not set them here + +## Increase number of concurrent ports/sockets +##+Q 65536 + +## Tweak GC to run more often +##-env ERL_FULLSWEEP_AFTER 10 diff --git a/core/rel/vm.args.eex b/core/rel/vm.args.eex new file mode 100644 index 0000000000..9456cfedcd --- /dev/null +++ b/core/rel/vm.args.eex @@ -0,0 +1,9 @@ +## Customize flags given to the VM: https://www.erlang.org/doc/man/erl.html +## -mode/-name/-sname/-setcookie are configured via env vars, do not set them here + +## Increase number of concurrent ports/sockets +##+Q 65536 + +## Tweak GC to run more often +##-env ERL_FULLSWEEP_AFTER 10 +-kernel inet_dist_listen_min 4370 inet_dist_listen_max 4500 \ No newline at end of file