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

RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
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 records...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" =&gt; #BSON.ObjectId&lt;58eb1a7a9ad169198c3dXXXX&gt;, "email" =&gt; ...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New

We're in Beta

About us Mission Statement