justinbkay

justinbkay

Hi,

I have a small cluster of Elixir nodes and I want to run a function on each node in the cluster and display the output on a liveview page. How’s the best way to go about running the function on each node in Node.list(), awaiting the response from each one? I’ve seen some examples using Node.spawn, and I know there’s an async/await syntax in Elixir. Looking for some guidance. Thanks!

Showing Posts 1 to 7

RudManusachi

RudManusachi

There are functions in :rpc module :rpc.call, :rpc.cast, :rpc.multicall etc. see rpc — OTP 29.0.2 (kernel 11.0.2)
Can be used as

{results, failed_nodes} = :rpc.multicall(Node.list(), mod, fun, args)

Could you please tell more about the scenario, the connection between the user interaction through liveview and distributed nodes? To give an idea why I’m asking is, for example, sometimes all we need is to broadcast data updates that happened on one node to all users connected to any node in the cluster through liveview, in that case Phoenix.PubSub broadcast could be enough and no need to manually call a function on each node. But YMMV =)

justinbkay

justinbkay OP

I’m trying to collect information from a log file on each node in the cluster and show the results on a liveview page. I want to enter some information on which to base a search, have each node run a search and report back the results. I don’t think Phoenix.PubSub comes into play here.

josevalim

josevalim

Creator of Elixir

Phoenix.PubSub could be used for this too. You could have a process running on each node that subscribes to a topic called “log_tailers”. Then you broadcast on said topic something like “give me the last 10 lines” and all subscribed processes would return to you the relevant info. :rpc and friends work too.

justinbkay

justinbkay OP

I think the :rpc.multicall is exactly what I want, but I can’t get it working. I’m trying this:

:rpc.multicall(Node.list(), :"Elixir.Appapi.Log.FindPayload", :start, '13102496')

but getting an error:

{[
   badrpc: {:EXIT,
    {:undef, [{Appapi.Log.FindPayload, :start, '13102496', []}]}}
 ], []}

This is the call in IEx

Appapi.Log.FindPayload.start("13102496")

What am I missing?

josevalim

josevalim

Creator of Elixir

I am guessing here, two possible reasons:

  1. The fourth argument to multicall needs to be list of parameters, so you need: :rpc.multicall(Node.list(), Appapi.Log.FindPayload, :start, ['13102496'])

  2. The module Appapi.Log.FindPayload is not loaded in the remote node

justinbkay

justinbkay OP

It was the arguments being in a list. Thank you @josevalim!

Erynn

Erynn

will it work for all nodes if all nodes have connect_all set false and connected in a ring manually like 1 connected to 2, 2 to 3, 3 to 4, 4 to 5. will rpc.multicall work from node 3, if i have to fetch data from all nodes?

— All posts loaded —

Where Next? Top

Trending in Questions Top

Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
Onor.io
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
Trolleger
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
matt-savvy
Anyone here using Honeybadger? My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of Bandit.HTTPError...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
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
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews