josevalim

josevalim

Creator of Elixir

Hello everyone,

I would like to propose the addition of the Registry project to Elixir:

https://github.com/elixir-lang/registry

The Registry project is a local and scalable key-value process storage in Elixir. It encapsulates 3 known use cases:

  • Process registry: to register process with dynamic names. Often Elixir developers need to rely on gproc or other tools.
  • Code dispatching: dispatch a module/function associated to a given key
  • PubSub implementation: send messages to local processes registered under a given topic

There are probably other use cases waiting to be discovered. :slight_smile:
You can learn more in the documentation:

http://elixir-lang.org/docs/registry/

The project clocks only 700LOC with documentation and performs well. We have extracted, improved and generalized the patterns from Phoenix.PubSub, the implementation used to manage and publish messages to 2 million subscribers.

When benchmarking thousands of processes registering serially, it is twice slower than local atoms, albeit 33% faster than gproc. On concurrent cases, it distributes well across all cores, becoming only 15% slower than local atoms, and 3x faster than gproc on a machine with two cores (gproc seems to be serial with its default configurations so the difference will be even bigger on more cores).

Please give it a try and let us know what you think.

Showing Posts 1 to 10

JEG2

JEG2

Author of Designing Elixir Systems with OTP

I am so excited about the possibility of having this built-in!

OvermindDL1

OvermindDL1

Ooo, so basically an Elixirfied :gproc it looks like? That is awesome if so! ^.^

EDIT: Indeed it does, a bit more simplified in the docs as I’m not seeing anything like :gprocs local and remote distinctions or pubsub helpers and such, but it looks like the pubsub helpers can be build on what is here, and the local and remote distinctions are probably not necessary if it is naturally distributed. :slight_smile:

josevalim

josevalim OP

Creator of Elixir

Its API is quite simpler than gproc’s. There is no support for distribution as well, it is by definition local. One reason why we are hesitant on tackling any distributed registry as part of Elixir is because such is already part of the OTP team plans.

OvermindDL1

OvermindDL1

Ooo, I’ve apparently not kept up with the OTP doings, that would be fascinating.

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

What would the relationship between this and those OTP plans be once they come to fruition?

ChrisYammine

ChrisYammine

Neat! Definitely giving it a try :slight_smile:

belaustegui

belaustegui

Wonderful! The implementation seems very clean and understandable :slight_smile:

Noob question: what would be the utility of having multiple partitions for the same Registry? Looking at the code I see that the registry uses only one by default. In which cases should I use more partitions than the default one?

Qqwy

Qqwy

TypeCheck Core Team

This is very interesting!

I believe it would be great to have this become part of Elixir’s core or at least the ‘officially maintained packages’, as it is a very common use case.

What was the main reason behind starting this project? In the first post you mentioned that Registry is somewhat faster than gproc: Was this (make it faster) the main reason to start building this? Or are there features that you feel are missing from gproc and other existing alternatives that are important enough to start something new?

gmile

gmile

Can you please point to a relevant discussion?

josevalim

josevalim OP

Creator of Elixir

This is local, the OTP one is distributed. You shouldn’t use the OTP one to store local data, as looking up or storing information may require messages across nodes.

On my benchmarks, the use of partitions have only been justified for the pubsub/dispatch use cases. For the unique registry, I couldn’t find a case yet where increasing the number of partitions matter. However, my current machine has only 2 cores. Maybe a partitioned unique registry may matter on machines with 16+ cores.

:gproc is a great project, albeit I find its API confusing (YMMV). If you asked me about a registry in Elixir six months ago, the answer would likely be no. So what has changed?

  1. I confirmed with the OTP team they have no plans to tackle a local registry
  2. While working on a separate project wth @chrismccord, we realized we could generalize the PubSub implementation while keeping the scalability aspects of Phoenix.PubSub
  3. The generalization of PubSub made it useful for at least 2 other common cases: :via lookups and module/function dispatching. :via lookups is a frequently required feature. Plus I am using module/function dispatching to replace GenEvent in another app and we will explore it instead of GenEvent in Logger too.

Being faster than gproc is a perk, although the registry was designed to scale with multiple cores. Work in the registry is always done on the client, there is no centralized entity, and that’s another useful pattern to have in hand.

In other words, there isn’t a single reason. We found a generic solution that is performant and scalable and our reaction is that it can be very useful as part of the language.

Where Next? Top

Trending in News Top

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
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
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
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
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New

Latest on Elixir Forum

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews