din_S

din_S

I want to run different instances of the same app (not copies of the same app) on the same server (clustering) using different ports, so I used libcluster library and did the following (in application.ex):

def start(_type, _args) do
    import Supervisor.Spec
    # Define Topologies for clustering
    topologies = [
      example: [
        strategy: Cluster.Strategy.Gossip
      ]
    ]
    # List all child processes to be supervised
    children = [
      # For Clustering
      {Cluster.Supervisor, [topologies, [name: MyApp.ClusterSupervisor]]},
      # Start the endpoint when the application starts
      supervisor(MyAppWeb.Endpoint, []),
      {ConCache, [name: :my_cache, ttl_check_interval: false]}
    ]

    # See https://hexdocs.pm/elixir/Supervisor.html
    # for other strategies and supported options
    opts = [strategy: :one_for_one, name: MyApp.Supervisor]
    result = Supervisor.start_link(children, opts)
end

I even tried this:

topologies = [
      example: [
        strategy: Cluster.Strategy.Gossip,
        config: [hosts: [:"a@127.0.0.1", :"b@127.0.0.1",:"b@127.0.0.1",:"d@127.0.0.1"]],
      ]
    ]

but when I tried the following on the server (Ubuntu 18):

 PORT=3000 elixir --sname a -S mix phx.server

then

 PORT=3001 elixir --sname b -S mix phx.server

I get the following error

** (Mix) Could not start application my_app: MyApp.Application.start(:normal, []) returned an error: shutdown: failed to start child: MyAppWeb.Endpoint
    ** (EXIT) shutdown: failed to start child: {:ranch_listener_sup, MyAppWeb.Endpoint.HTTP}
        ** (EXIT) shutdown: failed to start child: :ranch_acceptors_sup
            ** (EXIT) {:listen_error, MyAppWeb.Endpoint.HTTP, :eaddrinuse}


what should I do to make it work.

Showing Posts 1 to 6

kokolegorille

kokolegorille

You should check after starting first server if port 3000 is answering, if not, check port 4000.

I usually have to update my dev config file to do this…

http: [port: 4000],

# Replace by this, which is not the default

http: [
  port: System.get_env("PORT") || 4000
]

… and then I can pass PORT on startup.

din_S

din_S OP

After starting the first server, the application is answering correctly on the port,
because my config is like this

http: [
  port: System.get_env("PORT") || 3000
]

the problem is in running the app on other ports on the same time

kokolegorille

kokolegorille

I have tested this on a Phoenix without libcluster and it works for me.

I also have a libcluster, swarm project, but it uses Cowboy instead of Phoenix.

This might not help You, but I use Epmd strategy, and my config is standard to libcluster doc.

config :libcluster, topologies: [
  example_1: [
    strategy: Cluster.Strategy.Epmd,
    config: [hosts: [
      :node1@localhost,
      :node2@localhost,
      :node3@localhost,
    ]],
  ],

  example_2: [
    strategy: Cluster.Strategy.Gossip,
  ]
]

and I start nodes like this

$ iex --sname node1@localhost -S mix
$ PORT=4001 iex --sname node2@localhost -S mix
$ PORT=4002 iex --sname node3@localhost -S mix

It works, but this is not using Phoenix, but Cowboy.

din_S

din_S OP

Just a question, why it worked with the previous command and not this command

$ PORT=4002 iex --sname node3@localhost -S mix phx.server

and would the apps work without determining phx.server or not ?

and when I tried this command
netstat -nlp | grep beam
I got the following output (without 3001 or 3002)

tcp        0      0 0.0.0.0:43145           0.0.0.0:*               LISTEN      p1/beam.smp
tcp        0      0 0.0.0.0:3000            0.0.0.0:*               LISTEN      p2/beam.smp
tcp        0      0 0.0.0.0:40667           0.0.0.0:*               LISTEN      p3/beam.smp
tcp        0      0 0.0.0.0:36507           0.0.0.0:*               LISTEN      p4/beam.smp
udp        0      0 0.0.0.0:45892           0.0.0.0:*                           p5/beam.smp
udp        0      0 0.0.0.0:45892           0.0.0.0:*                           p6/beam.smp
udp        0      0 0.0.0.0:45892           0.0.0.0:*                           p7/beam.smp

ofcourse sudo netstat -nlp | grep 3001 and sudo netstat -nlp | grep 3002 give me nothing

din_S

din_S OP

I tried the other approach and it worked correctly, thanks a lot :slight_smile:

but it really bothers me that it didn’t work with libcluster and without knowing why

Mack_Akdas

Mack_Akdas

Hi Din_s,
I see a replication, maybe irrelevant to what you are looking for, but this should not be there, shouldn’t that not be a ‘c’ ?

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
ryanwinchester
apply_graft/2 doesn’t rewrite an add_many sub-workflow’s deps on an add step. Grafted jobs cancel with “upstream job was deleted” Version...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews