Giter VIP home page Giter VIP logo

ex_hash_ring's Introduction

ExHashRing

CI Hex.pm Version Hex.pm License HexDocs

A pure Elixir consistent hash ring implemention based on the excellent C hash-ring lib by Chris Moos.

ExHashRing is a production ready library actively maintained and in use at Discord.

ExHashRing provides the following features.

  • Lookup optimized ring storage. A ring is stored in an ETS table which provides excellent lookup performance.
  • Key overrides that allow the client to pin a key to a member.
  • Configurable replica count for virtual nodes.
  • Configurable history that allows for stable lookups over time.

Installation

Add it to mix.exs.

defp deps do
  [{:ex_hash_ring, "~> 6.0"}]
end

Upgrading to 6.0.0

Version 6.0.0 introduces a number of breaking changes. Refer to the Upgrade Guide for instructions.

Quickstart

Each Ring is managed by a GenServer, here's an example of starting an empty Ring.

iex(1)> alias ExHashRing.Ring
ExHashRing.Ring
iex(2)> {:ok, ring} = Ring.start_link()
{:ok, #PID<0.166.0>}

We can add a single node with add_node/2

iex(3)> Ring.add_node(ring, "a")
{:ok, [{"a", 512}]}

The 512 above is the number of replicas for this node. Since we did not specify a custom number of replicas, it was added with the default for this Ring, which itself defaults to 512. We can control the number of default replicas when we start_link the Ring and we can control the number of replicas on a per-node basis.

We can add another node with a custom replica count with add_node/3

iex(4)> Ring.add_node(ring, "b", 100)
{:ok, [{"b", 100}, {"a", 512}]}

Now that we have some nodes we can use our Ring to map keys to nodes with the find_node/2 function.

iex(5)> Ring.find_node(ring, "key1")
{:ok, "a"}
iex(6)> Ring.find_node(ring, "key37")
{:ok, "b"}

Documentation

The Quickstart above just scratches the surface of the functionality that ExHashRing provides. For more details see the HexDocs

Configuration

ExHashRing exposes some configuration options under the :ex_hash_ring key.

Key Description Default
:depth Default history depth for new rings 1
:gc_delay The amount of time, in milliseconds, to wait before garbage collecting stale generations 10_000
:replicas Default replicas setting for new rings 512

License

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

ex_hash_ring's People

Contributors

gmjosack avatar ihumanable avatar jhgg avatar likeanocean avatar scohen avatar tcyrus avatar vishnevskiy avatar ypisetsky 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  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

ex_hash_ring's Issues

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.