ketama 分布式hash算法

Hash

不同的输入可能会散列成相同的输出,而不可能从散列值来唯一的确定输入值,简单的说就是一种将任意长度的消息压缩到某一固定长度的消息摘要的函数


import(
	"gotest/hash/cityhash"
	"gopkg.in/mgo.v2/bson"
	"fmt"
	"time"

)

func main(){
	for{
		subKey := bson.NewObjectId().Hex()
		hValue := cityhash.CityHash32([]byte(subKey), uint32(len(subKey)))
		idx := hValue % 100
		fmt.Printf("hValue: %d, %d\n", hValue, idx)
		time.Sleep(1 * time.Second)

	}
}

ketama 一致性哈希算法

http://blog.codinglabs.org/articles/consistent-hashing.html

在这个圆圈上会映射两种元素的哈希值,一种元素是Object的哈希值,另一种元素是cache的哈希值,即计算机节点的哈希值

https://blog.csdn.net/shimadear/article/details/84450210

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章