Spyes
I have a Registry to create dynamic GenServers (each holding users’ parameters). I want to be able to take advantage of GenServer’s distributed multi_call / abcast, but since I’m using Registry, I must use a via tuple. Seems that mutli_call doesn’t like via tuples… Am I doing something wrong, is this by design, bug, or..? Thanks!
def start_link(uid, pid, params \\ %{}) do
GenServer.start_link(__MODULE__, [{pid, params}], name: via_tuple(uid))
end
defp via_tuple(uid), do: {:via, Registry, {@users_registry_name, uid}}
def get_params(uid) do
{replies, _bad} = via_tuple(uid) |> GenServer.multi_call(:get_params)
end
Error returned:
** (FunctionClauseError) no function clause matching in :gen_server.start_monitor/2
(stdlib) gen_server.erl:576: :gen_server.start_monitor(:node1@host, {:via, Registry, {:users_registry, "test"}})
(stdlib) gen_server.erl:467: :gen_server.send_nodes/5
(stdlib) gen_server.erl:425: :gen_server.do_multi_call/4
(project_name) lib/project_name/users_monitor.ex:17: ProjectName.UsersMonitor.get_params/1
Trending in Questions
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
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
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
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
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
Anyone here using Honeybadger?
My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of
Bandit.HTTPError...
New
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
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
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
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
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
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixir-ls
- #ai
- #elixirconf-us
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
Spyes
Digging through Erlang code for gen_server I see that start_monitor only accepts an atom as the name.. Erlang-OTP/lib/stdlib/src/gen_server.erl at master · blackberry/Erlang-OTP · GitHub
Any ideas how I can do something similar with as much ease as multi_call / abcast, or will I have to implement something myself?
josevalim
multi_callandabcastare about sending calls/casts across nodes rather than on the same machine.Spyes
Right, so my question is - how do I create dynamically-named GenServers and cast to them across multiple nodes?
What I mean is - I could have multiple GenServers with the same dynamically-generated name on different nodes. I want to be able to retrieve all params I’ve saved on those GenServers regardless of what node they are on.
arjan
I think you’re looking for a process registry that works in a distributed manner. Registry is only a local process registry, so maybe it’s not the right choice for you?
Maybe swarm or syn are a better match for your case.
Spyes
Thanks! I was thinking about Swarm actually, but was wondering if there was anything native that I could use instead. Also - do names in Swarm have to be unique? If I start two GenServers with the same name, will sending to that name send to both?
arjan
Swarm supports process grouping, that might do the trick?
Spyes
Hmm.. I’m not sure that it would. My scenario is this: a user connects with certain params, and I need to save those params. The same user can connect multiple times, with either similar or different params, but what is constant is his user_id (which in this case would be the “group”). I need to be able to retrieve all params saved under that user_id. My problem is that I could have many users connecting, so I can’t use a dynamically-created atom from the user_id as the group name..
voltone
One approach might be to have an aggregate store of user-related information, either on a centralised node or distributed using something like Riak Core or Mnesia, and have all nodes write to and read from there.
A simpler option, though potentially a bottleneck, would be the following: on each node run a regular named GenServer that dispatches to the local user processes through Registry. You can then use
multi_callandabcastto broadcast a tuple{uid, message}to that named process, and each node would unwrap the message and relay it locally using the via-tuple inuid. For calls you may have to spawn a process to handle the reply asynchronously, to avoid blocking the dispatcher.arjan
I think that it’s possible to use any term as the group name, as is usually
the case with systems like these.
gon782
Yes, both
synandswarmcan register arbitrary erlang terms as groups / names. I heartily recommendsyn, by the way. It’s very pleasant to work with. I’ve never used it for anything big, though, but it seems to do a fairly decent job of auto-synchronizing names/groups on/after netsplits.