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

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