GlobalConst

GlobalConst converts large Key-Value entities to a module to make fast accessing by thousands of processes.

Thanks

This library inspired by FastGlobal and mochiglobal. In our case, we has thousands of entities to save, and don't want to make so many modules. So Converting entities to a named module is a good approach.

Performance

benchmark name iterations average time
globalconst get 100000000 0.03 µs/op
globalconst get(10000keys) 100000000 0.06 µs/op
fastglobal get 10000000 0.29 µs/op
ets get 500000 7.93 µs/op
agent get 100000 14.95 µs/op

Installation

If available in Hex, the package can be installed by adding globalconst to your list of dependencies in mix.exs:

def deps do
[
{:globalconst, "~> 0.1.0"}
]
end

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/globalconst.

Usage

Create a new global const map and get the value

GlobalConst.new(GlobalMap, %{a: 1, b: 2})
1 == GlobalMap.get(:a)
2 == GlobalMap.get(:b)
{:error, :global_const_not_found} = GlobalMap.get(:c)
:default_value = GlobalMap.get(:c, :default_value)

License

GlobalConst is released under the MIT License. Check LICENSE file for more information.