sarat1669

sarat1669

Distributed Workers

I want to know how we can scale workers across nodes dynamically.
If a new node is connected to the cluster, how can the worker pool be notified of this?
What are the different strategies used?
And how do we start only the workers without starting the entire application in the new node?

Edit:
PS: I have never created a distributed system before

Most Liked

Matt

Matt

Elixir[Erlang]/OTP gives you the tools to design a distributed system. It is up to you to use the tools to implement the system you want. That is a great thing, I think. That allows great flexibility over your system. I’m going to give you a simplified example:

Now as far as dynamically attaching nodes to accept work. Perhaps you can have a GenServer running that looks for new oncoming nodes. This GenServer can watch Node.list and diff changes from the last check looking for nodes prefixed with “worker.” So if the previous list was [:"worker-1@10.0.1.100"] and the new list is [:"worker-1@10.0.1.100", :"worker-2@10.0.1.101"] your GenServer should detect that worker-2 is the new worker and perhaps tell another GenServer that handles work distribution that a new worker is online. The opposite behavior should work when a worker has been detected to leave.

As for work distribution, you asked if there is the ability to do so without running the application on the worker nodes. The answer is yes, but might be better to do so. Lets say you do not span a node running your application and spawn a link on a worker node like this (pull most recent profile, set encryption keys, and finalize the profile):

Node.spawn_link :"worker-1@10.0.1.100", fn ->
  with {:ok, profile} <- Profile.fetch_pending_profiles() do
    {:ok, _} = EncryptionService.set_enc_keys(profile)
    {:ok, _} = Profile.finalize_profile(profile)
  end
end

This would be a problem because you would receive an UndefinedFunctionError error on the worker node. This is because the worker node does not have the Profile or the EncryptionService modules. It is still possible to accomplish this without running the application on the worker node, but you would have to pass on the code to do all the database stuff, etc. You could avoid this issue by running the application on the worker nodes.

This was just my quick little comment…

Check these out too:

Where Next?

Popular in Questions Top

Tee
can someone please explain to me how Enum.reduce works with maps
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
quazar
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
Kagamiiiii
Student &amp; New to elixir. Nice language. I want to convert a english character, e.g. “a”, which is stored in a variable, to it’s asci...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
Exadra37
Sometimes I want to check if the input into a function is not a blank string. My first approach: defmodule Example do def do_stuff(s...
New
beno
I will often find my self writing things similar to: case some_value do nil -&gt; something() "" -&gt; something() _ -&gt; someth...
New
wernerlaude
In AR this is so simple @articles = current_user.articles How to do in Ecto? def index(conn, _params) do current_user = conn.assig...
New

Other popular topics Top

joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 27727 240
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 42633 214
New
johnnyicon
Hi all, I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I'm trying to use Postg...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New

We're in Beta

About us Mission Statement