Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow beeline to match Elixir's OTP naming #8

Merged
merged 6 commits into from
Oct 12, 2022

Conversation

pmonson711
Copy link
Contributor

@pmonson711 pmonson711 commented Oct 6, 2022

GenServer's in elixir can be one of several type structures.
https://hexdocs.pm/elixir/GenServer.html#t:name/0

The current implementation of Beeline only works with atoms (which match
to OTP's {:local, name} for named processes, but this limits the
places BeeLine can be used as it either leaks atoms or prevents from
having more than one GenServer of the same name running at a single time.
By updating the naming to include the global and via options the user
can decide how to control this instead of the library.

GenServer's in elixir can be one of several type structures.
https://hexdocs.pm/elixir/GenServer.html#t:name/0

The current implementation of Beeline only works with atoms (which match
to OTP's `{:local, name}` for named processes, but this limits the
places BeeLine can be used as it either leaks atoms or prevents from
having more ant one GenServer of the same name running at a single time.
By updating the naming to include the global and via options the user
can decide how to control this instead of the library.
@pmonson711
Copy link
Contributor Author

As a note on the mix.exs updates. This does require nimble_options >= 0.4.1, as before that it couldn't handle tuples.

@pmonson711 pmonson711 marked this pull request as ready for review October 11, 2022 15:48
{:global, Module.concat(base_name, appended_name)}
end

def name({:via, registry, {registry_name, base_name}}, appended_name) do
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just want to call out that this {:via...} pattern may not be complete. It will work with elixir's Registry module but it may not work with other common erlang registries like gproc.

@the-mikedavis
Copy link
Contributor

the-mikedavis commented Oct 11, 2022

There was a similar change in Broadway for allowing via tuples: dashbitco/broadway#239. They don't support global tuples but I don't think they're intentionally preventing them.

@pmonson711
Copy link
Contributor Author

It's interesting the approach Broadway takes with the overridable and no default implementation for the name mixed with a guard. That could work for Beeline as well but it seems like it might cause confusion in the config and the existing :name field. But I do think I'll add a guard that they added.

@pmonson711
Copy link
Contributor Author

I added a guard and updated the allowable names to match. It's slightly different than before.

Global names now match the OTP type where the second element of the tuple is a term.

Registry names are now limited to Elixir's Registry module, because that's all we test, and matches what Broadway does in their PR.

@@ -3,14 +3,13 @@ defmodule Beeline.Topology do

@behaviour GenServer

import Beeline.ProcessNaming, only: [name: 2]
alias __MODULE__.StageSupervisor

defstruct [:supervisor_pid, :config]

def start_link(config) do
Copy link
Member

@electricshaman electricshaman Oct 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this were start_link(config, options \\ []) we could just pass options directly to GenServer. Then, from another higher level module in your API, write the layer which handles the process name shenanigans. I feel a soapbox rant coming on.

Copy link
Member

@electricshaman electricshaman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is my first time ever seeing this library, so I don't have a lot of context built up about its design or usage. Best to mention that up front.

Your changes seem totally reasonable as an expansion of what's already here.

Beyond that, my unpopular thoughts: I don't understand the need for all of the ceremony around the naming of processes in the first place. I think it's admirable to want to hide the complexity of the supervision tree from clients, because honestly it's tedious and can be annoying to deal with, but in reality the people who will be using this library are already likely to know how to spin this up in their own application's supervision tree. This library seems to jump through a lot of hoops just to keep the Beeline API from exposing the process names and the supervision tree of stages. There's something to be said for that, but personally I find libraries like that frustrating to work with because they make assumptions about how I want to use OTP in my application and often times they restrict one's normal options like name and debug: [:trace].

@electricshaman
Copy link
Member

The more I look over Beeline, the more I think the above feedback is not really applicable here. Basically old man yelling at cloud situation.

@pmonson711 pmonson711 merged commit 9674bf9 into main Oct 12, 2022
@pmonson711 pmonson711 deleted the allow-dynamic-named-processes branch October 12, 2022 16:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants