{"id":17964806,"url":"https://github.com/sile/hash_ring","last_synced_at":"2025-07-30T01:34:21.269Z","repository":{"id":12338620,"uuid":"14980049","full_name":"sile/hash_ring","owner":"sile","description":"Implements consistent hashing in Erlang","archived":false,"fork":false,"pushed_at":"2020-12-10T00:48:48.000Z","size":1102,"stargazers_count":45,"open_issues_count":0,"forks_count":6,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-06-22T12:17:37.992Z","etag":null,"topics":["consistent-hashing","erlang"],"latest_commit_sha":null,"homepage":null,"language":"Erlang","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sile.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-12-06T10:35:11.000Z","updated_at":"2024-03-21T14:37:32.000Z","dependencies_parsed_at":"2022-09-19T07:30:44.425Z","dependency_job_id":null,"html_url":"https://github.com/sile/hash_ring","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"purl":"pkg:github/sile/hash_ring","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sile%2Fhash_ring","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sile%2Fhash_ring/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sile%2Fhash_ring/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sile%2Fhash_ring/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sile","download_url":"https://codeload.github.com/sile/hash_ring/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sile%2Fhash_ring/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267415161,"owners_count":24083743,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-27T02:00:11.917Z","response_time":82,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["consistent-hashing","erlang"],"created_at":"2024-10-29T12:08:48.162Z","updated_at":"2025-07-30T01:34:21.237Z","avatar_url":"https://github.com/sile.png","language":"Erlang","readme":"hash_ring\n=========\n\n[![hex.pm version](https://img.shields.io/hexpm/v/hash_ring.svg)](https://hex.pm/packages/hash_ring)\n[![Build Status](https://github.com/sile/hash_ring/workflows/build/badge.svg)](https://github.com/sile/hash_ring)\n[![Code Coverage](https://codecov.io/gh/sile/hash_ring/branch/master/graph/badge.svg)](https://codecov.io/gh/sile/hash_ring/branch/master)\n[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)\n\nAn implementation of consistent hashing algorithm.\n\nThis algorithm determines which nodes handles which items by hashing.\n\nConsisntent hashing is suitable to manage nodes in environments in which nodes dynamically joins and leaves.\n\nFor example, if a node leaves  the cluster, the items handled by the node should be reassigned to other nodes.\nBut other items can remain in the current nodes.\nThus in average case, only 1/N items are affected by the leaving (where 'N' is the number of nodes in the cluster).\n\nSee [Reference](#reference) for more information.\n\nBuild\n-----\n\nTo build the library for stand-alone usage:\n```sh\n$ git clone https://github.com/sile/hash_ring.git\n$ cd hash_ring\n$ rebar3 compile\n$ rebar3 shell\n$ \u003e hash_ring:module_info().\n```\n\nIf you want to use from your application:\n```erlang\n%% In your 'rebar.config'\n\n%% Add following lines\n{deps,\n [\n   hash_ring\n ]}.\n```\n\nExample\n-------\n\n```erlang\n%% Builds a consistent hash ring\n\u003e Nodes = hash_ring:list_to_nodes([a,b,c,d,e]).\n[{hash_ring_node,a,a,1},\n {hash_ring_node,b,b,1},\n {hash_ring_node,c,c,1},\n {hash_ring_node,d,d,1},\n {hash_ring_node,e,e,1}]\n\n\u003e Ring0 = hash_ring:make(Nodes).\n\n%% Finds the node which handles the item\n\u003e hash_ring:find_node(item_1, Ring0).\n{ok,{hash_ring_node,c,c,1}}\n\n%% Collects four nodes in descending order of priority\n\u003e hash_ring:collect_nodes(item_1, 4, Ring0).\n[{hash_ring_node,c,c,1},\n {hash_ring_node,e,e,1},\n {hash_ring_node,b,b,1},\n {hash_ring_node,d,d,1}]\n\n%% Addition of a node\n\u003e Ring1 = hash_ring:add_node(hash_ring_node:make(g), Ring0).\n\u003e hash_ring:collect_nodes(item_1, 4, Ring1).\n[{hash_ring_node,c,c,1},\n {hash_ring_node,e,e,1},\n {hash_ring_node,b,b,1},\n {hash_ring_node,g,g,1}] % The fourth node is changed from 'd' to 'g'\n\n%% Removal of a node\n\u003e Ring2 = hash_ring:remove_node(c, Ring1).\n\u003e hash_ring:collect_nodes(item_1, 4, Ring2).\n[{hash_ring_node,e,e,1}, % 'c' is removed but the remaining order is unchanged\n {hash_ring_node,b,b,1},\n {hash_ring_node,g,g,1},\n {hash_ring_node,d,d,1}]\n```\n\nAPI\n---\n\nSee [EDoc Documents](https://hexdocs.pm/hash_ring/)\n\nReference\n---------\n\n- https://en.wikipedia.org/wiki/Consistent_hashing\n- [Consistent Hashing and Random Trees: Distributed Caching Protocols for Relieving Hot Spots on the World Wide Web](https://www.akamai.com/us/en/multimedia/documents/technical-publication/consistent-hashing-and-random-trees-distributed-caching-protocols-for-relieving-hot-spots-on-the-world-wide-web-technical-publication.pdf)\n\nBenchmark\n---------\n\nA simple benchmark result for a 500 nodes ring.\n\n### Environment\n\n- OS: Ubuntu 15.10\n- CPU: Intel(R) Core(TM) i7-6600U CPU @ 2.60GHz\n- Erlang/OTP: OTP18.2 ([package](https://packages.erlang-solutions.com/erlang/esl-erlang/FLAVOUR_1_general/esl-erlang_18.2-1~ubuntu~wily_amd64.deb))\n\n### Result\n\nA result of `hash_ring_bench:bench(500, [])`.\n\n#### Toal Time and Heap Size\n\n| module            | make_time | add_time | remove_time | find_time | heap_size |\n|:------------------|----------:|---------:|------------:|----------:|----------:|\n| hash_ring_static  |    178 ms |  7166 ms |     2162 ms |  0.722 ms |   1406 KB |\n| hash_ring_dynamic |    396 ms |   381 ms |      367 ms |  1.141 ms |   6191 KB |\n\n#### Average Time per Node (or Item)\n\n| module            | add_time  | remove_time | find_time  |\n|:------------------|----------:|------------:|-----------:|\n| hash_ring_static  | 14.332 ms |    4.323 ms | 0.00144 ms |\n| hash_ring_dynamic |  0.762 ms |    0.734 ms | 0.00228 ms |\n\nLicense\n-------\n\nThis library is released under the MIT License.\nSee the [LICENSE](LICENSE) file for full license information.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsile%2Fhash_ring","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsile%2Fhash_ring","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsile%2Fhash_ring/lists"}