Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add simple DNS clustering #177

Closed
wants to merge 5 commits into from
Closed

Add simple DNS clustering #177

wants to merge 5 commits into from

Conversation

chrismccord
Copy link
Member

No description provided.


# discover nodes on init so we're connected before downstream children start
state =
do_discovery(%{
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can later introduce a :sync_init option or similar, but I feel like it's best to do synchronous discovery on init w/ timeout, to lessen races on downstream children starting without full mesh connections

@@ -83,6 +98,16 @@ defmodule Phoenix.PubSub.PG2 do
Supervisor.child_spec({Phoenix.PubSub.PG2Worker, {name, group}}, id: group)
end

children =
case System.get_env("PHX_CLUSTER_DNS") do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We really shouldn't be relying on env vars down here. Also, the cluster name is not related to PubSub, so I would say this functionality is out.

My suggestion is to add Phoenix.PubSub.DNSCluster as a service and have your Phoenix endpoint start it based on a config:

config :my_app, MyApp.Endpoint, dns_cluster: true

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not "related", but also the pg adapter is not useful if you aren't clustered, so it's still pretty well related. I'm fine with the endpoint starting it as well, but we have a problem in that the pubsub adapter is started above the endpoint for good reasons, so we'd be starting pubsub before clustering, which seems backwards, so I'm not sure?

Copy link
Member Author

@chrismccord chrismccord Jul 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So to put another way, I'm convinced we need a knob free way to get out of the box clustering, but if we don't put in the pubsub tree we don't have any other option to start it in the correct order, short of adding it explicitly to the children in phx.new

use GenServer
require Logger

defmodule Resolver do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it a separate module? 🤔

Copy link
Member Author

@chrismccord chrismccord Jul 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just for testing. Alternative is doc false'ing everything on the public DNSCluster

@chrismccord
Copy link
Member Author

Closing in favor of separate library https://github.com/phoenixframework/dns_cluster

@chrismccord chrismccord deleted the cm-dns-cluster branch July 12, 2023 00:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants