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

Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
earth10
Hi, I’m just starting to build a side-project with Elixir and Phoenix and doing some basic test with Elixir alone. What strikes me is th...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID&lt;0.412.0&gt; terminating ** (Postgrex.Error) FATAL...
New
jaysoifer
Is there a way to rollback a specific migration and only that one (“skipping” all the other ones)? Would mix ecto.rollback -v 200809061...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lists...
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New

Other popular topics Top

skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
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
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
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 31142 143
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
marick
I had some trouble figuring out how to make many-to-many associations work. Once I got it working, I wrote a blog post. Because I’m a nov...
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

We're in Beta

About us Mission Statement