假設有目前有n個伺服器,replica是d. (d>n)
現在新加入乙個伺服器s,影響之前n個伺服器的概率p:
現在環中有dn個區域, s要取d個點,一共有(dn)^d種取法。
要選中至少n個伺服器,取第乙個點,有dn種取法, 取第二點,有(d-1)n種取法,..., 取第n點,有(d-n+1)種取法.
故:p = dn*(d-1)n*(d-2)n*...*(d-n+1)n*(dn)^(d-n) / (dn)^d
= d*(d-1)*...*(d-n+1)/d^n
考慮影響至少x個伺服器,x可以等於n, n-1, ... , 1等
對x求期望:
e(x) = (d*(d-1)*...*(d-n+1)/d^n) * n +
(d*(d-1)*...*(d-n+2)/d^(n-1)) * (n-1) +
+1 //(影響至少一台伺服器的概率是100%)
root# ./conshash2.out
enter existsevercnt:1
affected server count: 1
they are:
100 //伺服器id從100開始自增分配
root# ./conshash2.out
enter existsevercnt:2
affected server count: 2
they are:
100 101
root# ./conshash2.out
enter existsevercnt:3
affected server count: 1
they are:
102
root# ./conshash2.out
enter existsevercnt:4
affected server count: 1
they are:
103
root# ./conshash2.out
enter existsevercnt:5
affected server count: 2
they are:
100 104
root# ./conshash2.out
enter existsevercnt:6
affected server count: 5
they are:
100 101 102 103 105
root# ./conshash2.out
enter existsevercnt:7
affected server count: 4
they are:
102 103 104 106
root# ./conshash2.out
enter existsevercnt:8
affected server count: 4
they are:
103 104 105 107
root# ./conshash2.out
enter existsevercnt:10
affected server count: 4
they are:
101 102 105 109
root# ./conshash2.out
enter existsevercnt:15
affected server count: 5
they are:
101 102 105 110 114
root# ./conshash2.out
enter existsevercnt:20
affected server count: 6
they are:
102 103 110 111 115 119
root# ./conshash2.out
enter existsevercnt:30
affected server count: 5
they are:
106 113 117 125 129
root# ./conshash2.out
enter existsevercnt:50
affected server count: 3
they are:
114 118 122
root# ./conshash2.out
enter existsevercnt:100
affected server count: 6
they are:
128 143 147 164 168 179
root# ./conshash2.out
enter existsevercnt:200
affected server count: 4
they are:
108 184 220 241
root# ./conshash2.out
enter existsevercnt:300
affected server count: 4
they are:
172 208 328 364
root# ./conshash2.out
enter existsevercnt:400
affected server count: 3
they are:
139 377 464
root#
一致性hash演算法 面試必備 一致性hash演算法
最近公司在招人,我們準備的問題中有一道是關於一致性hash演算法的問題,只有一些面試者能夠回答上來,而且答的也不是很全面,有的面試者只是聽說過,有的連聽都沒聽過,下面我把一致性hash演算法整理一下分享給大家 一致性雜湊演算法在1997年由麻省理工學院的karger等人在解決分布式cache中提出的...
一致性hash演算法虛擬節點 一致性hash演算法
hash 演算法也叫做雜湊演算法,他可以讓任意長度的資料m對映成為長度固定的值h。hash演算法的第乙個作用就是資料的快速儲存與查詢。寫過程式的人都知道,基本上主流的程式語言裡面都有個資料結構叫做map dictionary或者 hash table 它是根據key來直接訪問結果的資料結構。key的...
一致性hash演算法
july部落格16章開始 第一題 全排列,輸入乙個字串,列印出該字串中字元的所有排列 1.個人思路 回溯法建立的排序樹 2.july部落格 遞迴實現,依次固定第乙個字母,後面的交換,和上面描述的使用回溯法相似 c stl 演算法 next permutation的思想,關於next permutat...