nitram

nitram

Hello there,

I have a little follow up question for mi previous question referencing here. For small recap:

I was triing to make one library supervisor free for sake of reducing complexity, what worked quite well. The main problem was that it was used in ambrela where some applications were starting some server from lib and some were not and I need to awoid process already started while keep ability to take service and run it on its own. (server are quite memory heavy)

So today problem is that that memory heavy servers now need a start one server, server should by started of group of aplication in umbrella start at least one of the mentioned memory heavy servers. From mi point of view, the easiest solution would by to just make every memory heavy server supervisor which would start self and the dependent server, which would have name and would also use the already_started Process link trick:

def start_link(_ \\ nil) do
    __MODULE__
    |> GenServer.start_link(:ok, name: __MODULE__)
    |> start_link_response()
end
defp start_link_response({:error, {:already_started, pid}}) do
    true = Process.link(pid)
    {:ok, pid}
  end

defp start_link_response(response), do: response

Bat it seems somehow smelly, is there any more elixirish solution?

Showing Posts 1 to 5

lud

lud

You want to link to this process so the calling process will be exited if the “heavy” server exits ?

nitram

nitram OP

I have use cases for both, this is one of reasons why I would like to keep gen_server api, so every application could decide what will happend with it if server crash, some need restart and some can ignore that…

lud

lud

I think you are complicating things for no reason.

Your heavy server should be started, and should be registered somewhere (with it’s name or in a registry).
Then, any dependent server should use a monitor to be told when the heavy server exits, so they can wait for it to be restarted.

So, instead of starting the heavy process multiple times, you start it in your supervision tree only once.

nitram

nitram OP

But I have multiple applications in multiple umbrellas, so I don’t have single supervisor tree. One think that I consider now is to split common lib so it is solved by mix…

lud

lud

All the applications that depend on your heavy server should be started after the application that starts the heavy server. This way, the heavy server is aliver when your other applications start.

There is a way with Elixir/Erlang to configure the applications start order, but I do not know it myself.

— All posts loaded —

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
roeland
Kia ora, We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
bottlenecked
Hi all, I wanted to ask how the community is dealing with post-release steps. Today we have Ecto migrations, which make sure that the db...
New
rahultumpala
Hello, I have an Elixir backend that implements a custom protocol over TCP. I want to load test the backend and assess the performance o...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
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
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
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
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews