[erlang-questions] sharing config via a dynamically compiled module?

Erdem Aksu erdemaksu@REDACTED
Wed Oct 25 17:04:49 CEST 2017


Hello Benoit,

I am using following application:
https://github.com/pundunlabs/gb_reg

It keeps object code for the module in files for later recovery. It loads
the latest object code from files on application start.
One can share the object code(binary) in-between nodes and each node can
load the module. (code:load_binary/3)

There is no documentation, but usage is like following if you are
interested:
application:start(gb_reg),
{ok, Module} = gb_reg:new(Name), %% See new/2 that gets an Init list of
Key/Values.
gb_reg:insert(Module, Key, Value),
gb_reg:insert(Module, [{K1, V1},{K2, V2}]), %% File dumped once for all
entries.
Module:lookup(Key),
gb_reg:delete(Module, Key),
Module:entries(), %% Same as gb_reg:all(Module)
gb_reg:add_keys(Module, [K]), %% Two entries K -> Ref and Ref -> K are
created where Ref is auto incremented integer that is encoded as unsigned
integer.
gb_reg:purge(Module).

Cons:
  Slow insertion. Keeping configurations is a good use case for this if
they are not updated frequently.
Pros:
  gen_server serialise addition/deletion of new entries thus the file
access and code reload will be sequential.

I use this in a wide column database implementation, where I lookup Column
Id <-> Column Name at writes and reads to pack/unpack the data. And I use a
similar approach for keeping key (hash) ring for fast lookup on db shards.

Regards,
Erdem

On Wed, Oct 25, 2017 at 3:55 PM, Dmitry Kolesnikov <dmkolesnikov@REDACTED>
wrote:

> Hello,
>
> On 25 Oct 2017, at 16.27, Benoit Chesneau <bchesneau@REDACTED> wrote:
>
>  It seems lot of people are using ets to share a config generally. Maybe
> becauseit feels a little hackish ?
>
>
> The usage of code-as-a-config is “valid” approach. I’ve used that for some
> project. However, the reloading of config is something to consider. You
> need to use code:purge(…) and take all pain associated with it. The
> code-as-a-config works as build time config but runtime config is easy with
> build-in application:get_env…
>
>
> - Dmitry
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20171025/0629afd0/attachment.htm>


More information about the erlang-questions mailing list