Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
About: consistent hashing
Search
Harukasan
PRO
February 27, 2017
Technology
0
220
About: consistent hashing
Harukasan
PRO
February 27, 2017
Tweet
Share
More Decks by Harukasan
See All by Harukasan
PicoRabbit: a Tiny Presentation Device Powered by Ruby
harukasan
PRO
2
360
pixivを支える技術 / 技育CAMPアカデミア
harukasan
PRO
3
490
20240401 新卒研修 - ピクシブにおける技術領域
harukasan
PRO
1
800
ピクシブのコンテンツ配信基盤技術 / pixiv TECH SALON
harukasan
PRO
5
5.6k
Goにおける画像ファイル処理 / golang.tokyo #19
harukasan
PRO
7
6.7k
WebRTC動画をトランスコードする / Transcoding video streams from WebRTC
harukasan
PRO
5
1.6k
ImageFluxを支えるリモート開発 / 20171202
harukasan
PRO
2
1.8k
YAPC::Fukuoka 前夜祭LT / Yet Another Pawoo Commit logs
harukasan
PRO
0
3k
YAPC::Fukuoka lunch session
harukasan
PRO
1
3.1k
Other Decks in Technology
See All in Technology
Oracle Cloud Infrastructure IaaS 新機能アップデート 2025/03 - 2025/05
oracle4engineer
PRO
1
110
Kafka vs. Pulsar: Performance Evaluation by Petabyte-Scale Streaming Platform Providers
lycorptech_jp
PRO
1
290
単一Gitリポジトリから独立しました
lycorptech_jp
PRO
0
340
DevOpsDays Taipei 2025 - Opening Remarks
cheng_wei_chen
0
120
Generational ZGCのメモリ運用改善 - その物理メモリ使用量、本当に正しい?
tabatad
0
260
名刺メーカーDevグループ 紹介資料
sansan33
PRO
0
760
ai bot got sick (abc 2025s version)
kojira
0
120
Spring for GraphQLって実際どうなの?〜小規模スタートアップの事例紹介〜
kogayushi
0
140
Java 30周年記念! Javaの30年をふりかえる
skrb
4
2.6k
キャッシュレス決済のプロダクトから決済基盤への進化
b1a9id
0
200
やさしい認証認可
minorun365
PRO
13
2.6k
技術書典18結果報告
mutsumix
2
200
Featured
See All Featured
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
1
97
Why Our Code Smells
bkeepers
PRO
337
57k
The Cost Of JavaScript in 2023
addyosmani
49
8.3k
Building an army of robots
kneath
306
45k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
233
17k
Bootstrapping a Software Product
garrettdimon
PRO
307
110k
The World Runs on Bad Software
bkeepers
PRO
68
11k
It's Worth the Effort
3n
184
28k
Build your cross-platform service in a week with App Engine
jlugia
231
18k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
667
120k
StorybookのUI Testing Handbookを読んだ
zakiyama
30
5.8k
Code Reviewing Like a Champion
maltzj
524
40k
Transcript
ӋԍӏӑӞԍӠӧӜӏӾʂҍ҅ѥ҈ ӬӆӏӮװɒױґҭѭѷҵ
ѵѵ҉ѥѧӧӜӏԍӇҊґ
ΌҐӄـҴΌҐӦـӡҍðҬƾ҈ҁѥ Ҋѥѧī
ֿ ׀ ׁ ׅ ׆ ׇ ֿ־ ֿ ׀ ׁ
ׂ ׃ ׄ ӄـ Ӧـӡ
ֿ ׀ ׁ ׅ ׆ ׇ ֿ־ ֿ ׀ ׁ
ׂ ׃ ׄ ˅ˤҍґѵѧҌ҆҈ҝѹѥ Ӧـӡ
ѵҮѮ҉ѯҭҊ ؆!ҐӏӼـӟҺԍӇ ؆ӄӼӜӏӾҐåࢄشࠓ´҆҈ҭҥ҅ ؆Ҍҍѭѣҭҥ҅ҴҌҵѭͮѥײѺҍåð ……ҊѭҠѣѥүѥүҊ¸ê
˕ӏԍӯԃҌȠʂ פӺӐӾԅʂץ
ֿ ׀ ׁ ֿ ׀ ׁ %3 = 1 %3
= 2 %3 = 0 ׂ %3 = 1 ӺӐӾԅʂ ӦـӡҐ²ҴҊҭ ׃ ׄ %3 = 2 %3 = 0
ӺӐӾԅʂ ؆ÅҬѮχѵҫҌѱ҈ͮѷѿѧ ؆ӏԍӯԃ ؆ӦـӡҴϟՃѻҭҊѯҍŖő
ӺӐӾԅʂ ֿ ׀ ׁ ֿ ׀ ׁ %3 = 1
%3 = 2 %3 = 0 ׂ %3 = 1 ׃ ׄ %3 = 2 %3 = 0
ӺӐӾԅʂ ׂ ֿ ׀ ׁ ֿ ׀ ׁ %3 =
1 %3 = 2 %3 = 0 ׂ %3 = 1 ׃ ׄ %3 = 2 %3 = 0
ֿ ׀ ׁ ֿ ׀ ׁ %4 = 1 %4
= 2 %4 = 3 ׂ %4 = 0 ӺӐӾԅʂ ׂ ׃ ׄ %4 = 1 %4 = 2 ӦـӡҴϟՃѻҭҊѯҍŖő ׀¦߱ѻқ҈҉ȳѯȈѩѮˠੜ
פӺӐӾԅʂץґ ࣮ΆѮ؆୯҂ѮӦـӡҐϟՃ؏আѮŖő
ӋԍӏӑӞԍӠӧӜӏӾʂ • @_LE@YJFYF[@Q،TSZLZ[FS[ @ZKLSJ@SE@SETR YFFZLZ[YLC\[FE@DKLSJYT[TDTQZITYFQLF_LSJ T[ WT[ZTS[KF"TYQE"LEF"FC،ׇׇֿׅׯ • ࣮ΆҊѹ҈ґFRD@DKFEҐҁңҐF[@R@ѮȵĚ K[[WZזזJL[K\CאDTRזזPF[@R@
• SJLSaW@DKFY@IILDFY_FYҤ࠾ˉ
ӋԍӏӑӞԍӠӧӜӏӾʂ ؆ӧӜӏӾВґɠҍåƖѻҭґѼ ؆ӧӜӏӾВҴԂԍӇ ҍѹ҈࣮Ά
ֿ ׀ ׁ ӋԍӏӑӞԍӠӧӜӏӾʂ ӦـӡӄـҐѿҮҀҮҴęѺӧӜӏӾ̌БҍࣹӨ @ZK @ZK @ZK ׯ ׯ
ׯ ӧӜӏӾ̌Б
ֿ ׀ ׁ @ZK @ZK @ZK ׯ ׯ ׯ ӧӜӏӾ̌Б
ֿ ׀ ׁ ׂ ׃ ׄ @ZK @ZK @ZK @ZK @ZK @ZK ׯ ׯ ׯ ׯ ׯ ׯ ӋԍӏӑӞԍӠӧӜӏӾʂ ӦـӡӄـҐѿҮҀҮҴęѺӧӜӏӾ̌БҍࣹӨ
ֿ @ZK ׯ ֿ ׀ ׁ @ZK @ZK @ZK ׯ
ׯ ׯ ۙѥÃҴબ ֿ ׀ ׁ ׂ ׃ ׄ @ZK @ZK @ZK @ZK @ZK @ZK ׯ ׯ ׯ ׯ ׯ ׯ ֿ˕ ҐÃҴҊҭ ؼ ӧӜӏӾ̌Б ӋԍӏӑӞԍӠӧӜӏӾʂ ӦـӡӄـҐѿҮҀҮҴęѺӧӜӏӾ̌БҍࣹӨ
ӋԍӏӑӞԍӠӧӜӏӾʂ ؆ӧӜӏӾВґɠҍåƖѻҭґѼ ؕҌҐ҉ÅҫҌѥ ؆ȳѯȈҰҭҐґӧӜӏӾ̌БҐ϶҂ѳҐґѼ ؕҌҐ҉ϟՃѹҁҊѯҐӘӹـӐѮƀҌѥ
ֿ ׀ ׁ ϟՃѹҁҊѯҐӘӹـӐѮƀҌѥ @ZK @ZK @ZK ׯ ׯ ׯ
ӧӜӏӾ̌Б ֿ ׀ ׁ ׂ ׃ ׄ @ZK @ZK @ZK @ZK @ZK @ZK ׯ ׯ ׯ ׯ ׯ ׯ
ϟՃѹҁҊѯҐӘӹـӐѮƀҌѥ ӧӜӏӾ̌Б ֿ ׀ ׁ ׂ ׃ ׄ @ZK @ZK
@ZK @ZK @ZK @ZK ׯ ׯ ׯ ׯ ׯ ׯ ֿ ׀ ׁ @ZK @ZK @ZK ׯ ׯ ׯ ׂ @ZK ׯ ׂҴϟՃ
ϟՃѹҁҊѯҐӘӹـӐѮƀҌѥ ӧӜӏӾ̌Б ֿ ׀ ׁ ׂ ׃ ׄ @ZK @ZK
@ZK @ZK @ZK @ZK ׯ ׯ ׯ ׯ ׯ ׯ ֿ ׀ ׁ @ZK @ZK @ZK ׯ ׯ ׯ ۙѥÃҴબ ׂ @ZK ׯ ȳѯȈҰ҆ҁҐґׄ҂ѳ
ӋԍӏӑӞԍӠӧӜӏӾʂ ؆ÅҫҌѥ ؆ϟՃѹҁҊѯҐӘӹـӐѮƀҌѥ
ӧӜӏӾ̌Б ֿ @ZK ׯ ˅ˤҍґ ؟ֿذ׀
˅ˤҍґ ӧӜӏӾ̌Б ֿ ׀ @ZK @ZK ׯ ׯ ׀ҴϟՃѻҭҊ ؟ֿذ׀׃־أ
ӧӜӏӾ̌Б ֿ ׀ @ZK @ZK ׯ ׯ ׁ @ZK ׯ
˅ˤҍґ ؟׀ذׁ׀׃أ ׁҴϟՃѻҭҊ
ӧӜӏӾ̌Б ֿ ׀ @ZK @ZK ׯ ׯ ׁ @ZK ׯ
ׂ @ZK ׯ ˅ˤҍґ ؟ׁذׂ׀׃أ ׂҴϟՃѻҭҊ
ӋԍӏӑӞԍӠӧӜӏӾʂ ؆ÅҫҌѥ ؆ϟՃѹҁҊѯҐӘӹـӐѮƀҌѥ
ӋԍӏӑӞԍӠӧӜӏӾʂҐ࣮Ά F[@R@ҐńĘׯ
# ϋογϡؔ32bit unsigned intͷϋογϡΛฦ͢ # CRC32, MD5ͷ্Ґ32bitͳͲͰ࣮ func hash(key string)
uint32 { ... } # ϊʔυͷϋογϡΛܭࢉ for _, node := range nodes { # ͻͱͭͷϊʔυຖʹ160ݸͷϋογϡΛܭࢉ for i := 0; i < 160; i++ { k := fmt.Sprintf(“%s-%d”, node, i) # ϊʔυ໊ͱϋογϡͷϖΞΛՃ continuum.add(node, hash(k)) } } # ϋογϡͰιʔτ͓ͯ͘͠ sort.Sort(continuum) ֿאӦـӡӶӜӯҐܭࢉ
ֿאӦـӡӶӜӯҐܭࢉ ӧӜӏӾ̌Б ֿ @ZK ׯ ֿ҅ҐӦـӡҍରѹ ΌҐӧӜӏӾҴܭࢉ ذӧӜӏӾܭࢉҍҩҭÅҬҴЕɦ ؕ׀־־¿ѱҫѥ҉ůŲׯ
# ϋογϡͰιʔτ͓͚ͯ͠ೋ୳ࡧͰ୳ࡧͰ͖Δ func search(key string) string { v := hash(key)
i, j := 0, n for i < j { h := i + (j-i)/2 if (continuum.values[i] > v) { i = h + 1 } else { j = h } } return continuum.nodes[i] } ׀אӧӜӏӾҐ୳ࡧ
׀אӧӜӏӾҐ୳ࡧ ӧӜӏӾ̌Б _ @ZK ׯ ֿ ׀ ׁ @ZK @ZK
@ZK ׯ ׯ ׯ ׂ @ZK ׯ å୳ࡧ҉˕ۙѥӧӜӏӾҴʹŲ
ҠҊң ӋԍӏӑӞԍӠӧӜӏӾʂׯ ؆ÅҫҌѥ ؕӧӜӏӾВҊѹ҈ґ׃ ¯ׁ׀CL[ׁ׀ !؆ֿ̙ ؆ϟՃѹҁҊѯҐӘӹـӐѮƀҌѥ ؆࣮ΆҤӏԍӯԃ