1 Star 3 Fork 5

laodasbch / grokking-system-design

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
consistent-hashing.md 1.24 KB
一键复制 编辑 原始数据 按行查看 历史
Arjun Agarwal 提交于 2020-02-15 13:49 . Update consistent-hashing.md

Consistent Hashing

Simple hashing

Problems of simple hashing function key % n (n is the number of servers):

  • It is not horizontally scalable. Whenever a new cache host is added to the system, all existing mappings are broken.
  • It may not be load balanced, especially for non-uniformly distributed data. Some servers will become hot spots.

Consistent Hashing

  • Consistent hashing maps a key to an integer.
  • Imagine that the integers in the range are placed on a ring such that the values are wrapped around.
  • Given a list of servers, hash them to integers in the range.
  • To map a key to a server:
    • Hash it to a single integer.
    • Move clockwise on the ring until finding the first cache it encounters.
  • When the hash table is resized (a server is added or deleted), only k/n keys need to be remapped (k is the total number of keys, and n is the total number of servers).
  • To handle hot spots, add “virtual replicas” for caches.
    • Instead of mapping each cache to a single point on the ring, map it to multiple points on the ring (replicas). This way, each cache is associated with multiple portions of the ring.
    • If the hash function is “mixes well,” as the number of replicas increases, the keys will be more balanced.
1
https://gitee.com/laodasbch/grokking-system-design.git
git@gitee.com:laodasbch/grokking-system-design.git
laodasbch
grokking-system-design
grokking-system-design
master

搜索帮助