polypush135

polypush135

Trying to understand OTP apps a little better and distribution

I was thinking:

What if I could abstract some of my otp applications from in my phoenix app and move them to another server?

I got this idea because I wanted to see if I could not put one of my 3 free 256mb VMs from fly.io to use since I was hitting a out of memory error.

[info][   41.509215] Out of memory: Killed process 255 (beam.smp) total-vm:1880020kB, anon-rss:141076kB, file-rss:0kB, shmem-rss:69636kB, UID:65534 pgtables:624kB oom_score_adj:0
[error]could not make HTTP request to instance: connection closed before message completed
[info][os_mon] cpu supervisor port (cpu_sup): Erlang has closed
[info][os_mon] memory supervisor port (memsup): Erlang has closed
[info] INFO Main child exited with signal (with signal 'SIGKILL', core dumped? false)
[info] INFO Starting clean up.
[info] WARN hallpass exited, pid: 256, status: signal: 15 (SIGTERM)
[info] INFO Process appears to have been OOM killed!
[info]2023/08/16 00:12:28 listening on .....
[info][   43.303638] reboot: Restarting system
[info]Out of memory: Killed process

So say I have an app I want to break apart. I’m gonna go with libcluster for this example.

application.ex on server A

 def start(_type, _args) do
    topologies = [
      cluster_example: [
        strategy: Cluster.Strategy.Epmd,
        config: [
          hosts: [
            :"app@foo.dev",
            :"app@bar.dev"
          ]
        ]
      ]
    ]

    children = [
      # Start the Ecto repository
      ClusterExample.Repo,
      # Start the Telemetry supervisor
      ClusterExampleWeb.Telemetry,
      # Start a worker by calling: ClusterExample.Worker.start_link(arg)
      # {ClusterExample.Worker, arg}
      {Cluster.Supervisor, [topologies, [name: ClusterExample.ClusterSupervisor]]}
    ]

And then you got server B

 def start(_type, _args) do
    topologies = [
      cluster_example: [
        strategy: Cluster.Strategy.Epmd,
        config: [
          hosts: [
            :"app@foo.dev",
            :"app@bar.dev"
          ]
        ]
      ]
    ]

    children = [
      # Start the PubSub system
      {Phoenix.PubSub, name: ClusterExample.PubSub},
      # Start the Endpoint (http/https)
      ClusterExampleWeb.Endpoint,
      # Start a worker by calling: ClusterExample.Worker.start_link(arg)
      # {ClusterExample.Worker, arg}
      {Cluster.Supervisor, [topologies, [name: ClusterExample.ClusterSupervisor]]}
    ]

Would this work like I assume it would? In that I assume the app will route methods correctly to the given hosted apps?

I look at :observer.start() and I assume I should be able to move any of these apps to another server correct?

I guess I’m just not sure what that would look like.

Most Liked

fceruti

fceruti

I’m very interested in what others have to say about this.

I’ve been pondering similar questions in the context of a phoenix app that also uses Membrane framework: How to run certain applications or supervisors in certain machines. In this scenario, machine requirements are very different.

:eyes:

Where Next?

Popular in Discussions Top

andre1sk
A big advantage to Elixir is all the distributed goodness but for many applications running on multiple nodes having integrated Etcd, Zoo...
New
blackode
Elixir Upgrading is so Simple in Ubuntu and It worked for me Ubuntu 16.04 git clone https://github.com/elixir-lang/elixir.git cd elixir...
New
AstonJ
Please see the new poll here: Which code editor or IDE do you use? (Poll) (2022 Edition) It’s been a while since we first asked this, I...
208 31265 143
New
AstonJ
Are there any Elixir or Erlang libraries that help with this? I’ve been thinking how streaming services like twitch have exploded recentl...
New
Crowdhailer
I’ve been hearing much about the new formatter and it’s something I have been keen to try. I find examples buy far the most illuminating...
248 19327 150
New
mbenatti
Following https://github.com/tbrand/which_is_the_fastest |> https://raw.githubusercontent.com/tbrand/which_is_the_fastest/master/imgs...
New
RudManusachi
What configs will make sense to put to runtime.exs? – A bit of how I configure apps: I have generic configs in config/config.exs, dev...
New
ben-pr-p
In general I’ve been sticking to this community style guide GitHub - christopheradams/elixir_style_guide: A community driven style guide ...
New
Qqwy
Looking at the stacks that existing large companies have used, WhatsApp internally uses Mnesia to store the messages, while Discord uses ...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

Other popular topics Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a > b) do {:ok, "a"} end if (a < b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
AstonJ
Please see the new poll here: Which code editor or IDE do you use? (Poll) (2022 Edition) It’s been a while since we first asked this, I...
208 31265 143
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 52673 488
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement