GithubHelp home page GithubHelp logo

fastglobal's Introduction

FastGlobal

Master Hex.pm Version

The Erlang VM is great at many things, but quick access to large shared data is not one of them. Storing data in a single process results in overloading the process, using an ETS table gets more expensive to read as the data gets larger, and both require copying data to the calling process. If you have large infrequently changing data that needs to be accessed by thousands of processes there is a better way.

Erlang has an optimization called constant pools for functions that return static data, you can also compile modules at runtime. This method was originally popularized by mochiglobal. This module is an Elixir version with some optimizations such as generating the atom keys and reusing them.

Performance

benchmark name               iterations   average time
fastglobal get                 10000000   0.33 µs/op
ets get                          500000   7.64 µs/op
agent get                        100000   12.67 µs/op
fastglobal purge perf (100)         500   2846.26 µs/op
fastglobal put (5)                  500   3683.30 µs/op
fastglobal put (10)                 500   6449.98 µs/op
fastglobal put (100)                 50   44543.56 µs/op

Caveats

  • Compile times get slower as data size increases.
  • Compile times get slower the more processes are in the system. Erlang talks to each process when purging a module.
  • Getting a key that does not exist is expensive due to try/catch, put at least a nil value.
  • Creating atoms from strings is not cheap, use FastGlobal.new.

Usage

Add it to mix.exs

defp deps do
  [{:fastglobal, "~> 1.0"}]
end

And just use it as a global map.

data = %{
  a: 1,
  b: 2,
  c: [3, 4]
}
FastGlobal.put(:data, data)
data == FastGlobal.get(:data)

License

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

fastglobal's People

Contributors

seeekr avatar vishnevskiy avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.