Spyes

Spyes

Registry and multi_call / abcast

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

Marked As Solved

gon782

gon782

Yes, both syn and swarm can register arbitrary erlang terms as groups / names. I heartily recommend syn, 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.

Also Liked

arjan

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.

voltone

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_call and abcast to broadcast a tuple {uid, message} to that named process, and each node would unwrap the message and relay it locally using the via-tuple in uid. For calls you may have to spawn a process to handle the reply asynchronously, to avoid blocking the dispatcher.

Where Next?

Popular in Questions 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
tduccuong
Hi, is there any work on GUI with Elixir, that is similar to Electron/Javascript? My idea is to bundle Phoenix and BEAM into a single se...
New
Werner
Hi, I’m using Ubuntu 18.04 and after updating to OTP-24.0 yesterday i have this warning when I run “mix local.hex”: 14:57:30.512 [warn] ...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
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
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
idi527
I’ve been re-reading swift book again and noticed that multiline strings there don’t have a trailing line break, unlike in elixir iex(2)...
New

Other popular topics Top

senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
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
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
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> someth...
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
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New

We're in Beta

About us Mission Statement