Multiple websites on one machine

Hi guys :smiley:

I have a question about having “having multiple websites on one machine” (putting the topic very simply so I don’t inadvertently make confusion in my intent).

To provide some context: I’ve been happily working with Elixir/Phoenix for the past 4-5 years, doing some small jobs for my friends. I usually am on a very tight budget (my friends are cheapskates :stuck_out_tongue:), so I try to do everything on one very low-spec VPS (one per friend).

Sometimes it so happens that my friends want multiple public-facing sites. When I tried to run two separate Phoenix projects on the same machine, one appeared to be running out of memory, while the other hogged all the memory for itself.

I have solved this issue previously by making multiple Endpoints in one project on different ports and ran it behind Caddy.

That worked well, but now I am doing a little bit more complicated project, which requires 3(+) domains, different apps and a very low payload (per-app assets, layouts etc.). I’ve tried to tackle this, but honestly the project directory now appears to be a giant convoluted mess now, into which I detest delving back into.

Questions from a dilettante to pros like you:

  1. Is there a way to run multiple projects on one ((low-spec)) machine without running out of memory, i.e. without the beam.smp processes fighting a last man standing type gladiator battle every time I try to start them? Honestly that would be the best solution, because it feels like I am fighting Phoenix at this point.
  2. If not, is there a good way of structuring my project for separate web apps, so that its assets, generated assets (like .js, .css files) and Elixir code runs neatly in one node? I read about generating an --umbrella project, but that didn’t seem to get me any further.

Thanks :heart:

C.

Running multiple endpoints in the same release is easy:

Your problem of running out of memory is something specific to your code or environment, not intrinsic to Elixir/Phoenix.

1 Like

Agreed. I have 2 small Elixir/Phoenix projects running on a Debian server, and the whole server uses less then 1GB of RAM (And I think that includes 2 Dockerized Postgres instances…).

Also, I would stay away from umbrella projects as a code organization tool. If you don’t know if you need an umbrella, then you don’t need one IMO. I find that they are typically more trouble than they are worth.

I would say you should look into using Erlang/Elixir-based profiling tools on your services to find your bottlenecks.

You should also share some more info about your setup. Are you using vanilla deployments, Docker, etc.?

3 Likes