【翻译/介绍】jump consistent hash:零内存消耗,均匀,快速,简洁,来自Google的一致性哈希算法 [2015-03-13]
简介 jump consistent hash是一种一致性哈希算法, 此算法 零内存消耗 , 均匀分配 , 快速 ,并且 只有5行代码 。 此算法适合使用在分shard的分布式存储系统中 。 此算法的作者是 Google 的 John Lamping 和 Eric Veach,论文原文在 http://arxiv.org/ftp/arxiv/papers/1406/1406.2294.pdf 完整代码: int32_t JumpConsistentHash(uint64_t key, int32_t num_buckets) { int64_t b = -1, j = 0; while (j < num_buckets) { b = j; key = key * 2862933555777941757ULL + 1; j = (b + 1) * (double(1LL << 31) / double((key >> 33) + 1)); } return b; } 输入是一个64位的key,和桶的数量(一般对应服务器的数量),输出是一个桶的编号。 原理解释: 下面byron根据论文的推导过程,做个翻译: jump consistent hash的设计目标是: 平衡性,把对象均匀地分布在所有桶中。 单调性,当桶的数量变化时,只需要把一些对象从旧桶移动到新桶,不需要做其它移动。