Elixir. Process Registry. Erlang Term Storage.

ETS table

Give us a message if you’re interested in Blockchain and FinTech software development or just say Hi at Pharos Production Inc.

This is the third article from Process Registry series. You can find previous two here

To increase lookup performance we should add a way better storage rather than Map. That’s ETS — Erlang Term Storage — blazingly fast in-memory key-value storage.

Almost nothing has changed in API, the only difference is in whereis_name function. It doesn’t call gen_server callback any more, now client will perform all lookup queries. We just pass a registry module and a key and match key with a result. Very straightforward.

ETS lookup

Also, there are no new callbacks at all. We just use what we already have but with map replaced with ETS. Also, there is no state in registry gen_server any more. All values are inside the ETS table.

Registry callbacks

In init callback we initialize ETS table with parameters:

  • :named_table — to identify table by its name;
  • :protected — this is a default setting for the access rights. The owner process can read and write to the table, other processes only read;
  • :set — the table is a set. One key, one object, no order among objects.

Register_name has only one change — it adds a new row to the table with a key as a key and PID has a value.

Unregister_name removes matching row from the table.

DOWN handle_info callback do the same as unregister_name but using PID as a matching pattern because there is no information about the key.

DONE

Link to Github repo pharosproduction/process-registry

Thanks for reading!

--

--

Dmytro Nasyrov
Pharos Production

We build high-load software. Pharos Production founder and CTO.