Giter Club home page Giter Club 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

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fastglobal's Issues

Discord.py on Mac Air

Hello to whoever is reading this. I’m EmmaFromNorway#1967 and I’m in need of help regarding python and Discord. Python does not let me install discord.py and I’m not sure as why. I’ve done certain research and apparently I need to download another program. Is this true? Please help as I’m thinking of making my own bot. Thank you for your time reading this :)

Getting All Keys

The library doesn't appear to implement a way to view all the keys that are available. Is this doable?

Elixir compile time

Hey, sorry about posting here, but I've read your blog posts about Elixir and had a question I wanted to go directly to the discord eng team AND be google-able since I couldn't find an answer on google :)

You guys probably have the largest Elixir/Erlang code base that I'm aware of. We also chose Elixir, and its GREAT so far, but we have team members with lots of experience in a huge scala codebase and they have the hope that as our codebase grows, it won't be as slow to compile as scala was. Any thoughts on that? Even with your huge codebase, are your incremental compiles still instant? How long does it take to compile form scratch? Thanks!

Setting value globally across cluster

If I want to store value globally across cluster of EVM nodes, this lib will probably not work.

What do you think about implementing this functionality?

My discord id is hacked

Hey my discord id was hacked recently can anyone help me discord isnt replying to my mails

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.