Distributed Hash Tables: Chord - UCL Computer Science

43
Distributed Hash Tables: Chord Brad Karp (with many slides contributed by Robert Morris) UCL Computer Science CS M038 / GZ06 24 th January 2012

Transcript of Distributed Hash Tables: Chord - UCL Computer Science

Page 1: Distributed Hash Tables: Chord - UCL Computer Science

Distributed Hash Tables: Chord Brad Karp

(with many slides contributed by Robert Morris)

UCL Computer Science

CS M038 / GZ06 24th January 2012

Page 2: Distributed Hash Tables: Chord - UCL Computer Science

2

Today: DHTs, P2P

•  Distributed Hash Tables: a building block •  Applications built atop them

•  Your task: “Why DHTs?” – vs. centralized servers? (we’ll return to this

question at the end of lecture) – vs. non-DHT P2P systems?

Page 3: Distributed Hash Tables: Chord - UCL Computer Science

3

What Is a P2P System?

•  A distributed system architecture: –  No centralized control –  Nodes are symmetric in function

•  Large number of unreliable nodes •  Enabled by technology improvements

Node

Node

Node Node

Node

Internet

Page 4: Distributed Hash Tables: Chord - UCL Computer Science

4

The Promise of P2P Computing

•  High capacity through parallelism: –  Many disks –  Many network connections –  Many CPUs

•  Reliability: –  Many replicas –  Geographic distribution

•  Automatic configuration •  Useful in public and proprietary settings

Page 5: Distributed Hash Tables: Chord - UCL Computer Science

5

What Is a DHT?

•  Single-node hash table: key = Hash(name) put(key, value) get(key) -> value – Service: O(1) storage

•  How do I do this across millions of hosts on the Internet? – Distributed Hash Table

Page 6: Distributed Hash Tables: Chord - UCL Computer Science

6

What Is a DHT? (and why?)

Distributed Hash Table: key = Hash(data) lookup(key) -> IP address (Chord) send-RPC(IP address, PUT, key, value) send-RPC(IP address, GET, key) -> value

Possibly a first step towards truly large-scale distributed systems –  a tuple in a global database engine –  a data block in a global file system –  rare.mp3 in a P2P file-sharing system

Page 7: Distributed Hash Tables: Chord - UCL Computer Science

7

DHT Factoring

Distributed hash table

Distributed application get (key) data

node node node ….

put(key, data)

Lookup service lookup(key) node IP address

•  Application may be distributed over many nodes •  DHT distributes data storage over many nodes

(DHash)

(Chord)

Page 8: Distributed Hash Tables: Chord - UCL Computer Science

8

Why the put()/get() interface?

•  API supports a wide range of applications – DHT imposes no structure/meaning on keys

•  Key/value pairs are persistent and global – Can store keys in other DHT values – And thus build complex data structures

Page 9: Distributed Hash Tables: Chord - UCL Computer Science

9

Why Might DHT Design Be Hard?

•  Decentralized: no central authority •  Scalable: low network traffic overhead •  Efficient: find items quickly (latency) •  Dynamic: nodes fail, new nodes join •  General-purpose: flexible naming

Page 10: Distributed Hash Tables: Chord - UCL Computer Science

10

The Lookup Problem

Internet

N1 N2 N3

N6 N5 N4

Publisher

Put (Key=“title” Value=file data…) Client

Get(key=“title”)

?

•  At the heart of all DHTs

Page 11: Distributed Hash Tables: Chord - UCL Computer Science

11

Motivation: Centralized Lookup (Napster)

Publisher@

Client

Lookup(“title”)

N6

N9 N7

DB

N8

N3

N2 N1 SetLoc(“title”, N4)

Simple, but O(N) state and a single point of failure

Key=“title” Value=file data…

N4

Page 12: Distributed Hash Tables: Chord - UCL Computer Science

12

Motivation: Flooded Queries (Gnutella)

N4 Publisher@ Client

N6

N9

N7 N8

N3

N2 N1

Robust, but worst case O(N) messages per lookup

Key=“title” Value=file data…

Lookup(“title”)

Page 13: Distributed Hash Tables: Chord - UCL Computer Science

13

Motivation: FreeDB, Routed DHT Queries (Chord, &c.)

N4 Publisher

Client

N6

N9

N7 N8

N3

N2 N1

Lookup(H(audio data))

Key=H(audio data) Value={artist,

album title,

track title}

Page 14: Distributed Hash Tables: Chord - UCL Computer Science

14

DHT Applications

They’re not just for stealing music anymore… – global file systems [OceanStore, CFS, PAST,

Pastiche, UsenetDHT] – naming services [Chord-DNS, Twine, SFR] – DB query processing [PIER, Wisc] –  Internet-scale data structures [PHT, Cone,

SkipGraphs] – communication services [i3, MCAN, Bayeux] – event notification [Scribe, Herald] – File sharing [OverNet]

Page 15: Distributed Hash Tables: Chord - UCL Computer Science

15

Chord Lookup Algorithm Properties

•  Interface: lookup(key) → IP address •  Efficient: O(log N) messages per lookup

– N is the total number of servers

•  Scalable: O(log N) state per node •  Robust: survives massive failures •  Simple to analyze

Page 16: Distributed Hash Tables: Chord - UCL Computer Science

16

Chord IDs

•  Key identifier = SHA-1(key) •  Node identifier = SHA-1(IP address) •  SHA-1 distributes both uniformly

•  How to map key IDs to node IDs?

Page 17: Distributed Hash Tables: Chord - UCL Computer Science

17

Consistent Hashing [Karger 97]

A key is stored at its successor: node with next higher ID

K80"

N32"

N90"

N105" K20"

K5"

Circular 7-bit ID space

Key 5 Node 105

Page 18: Distributed Hash Tables: Chord - UCL Computer Science

18

Basic Lookup

N32"

N90"

N105"

N60"

N10"N120"

K80"

“Where is key 80?”

“N90 has K80”

Page 19: Distributed Hash Tables: Chord - UCL Computer Science

19

Simple lookup algorithm

Lookup(my-id, key-id) n = my successor if my-id < n < key-id call Lookup(key-id) on node n // next hop else return my successor // done

•  Correctness depends only on successors

Page 20: Distributed Hash Tables: Chord - UCL Computer Science

20

“Finger Table” Allows log(N)-time Lookups

N80"

½"¼"

1/8!

1/16!1/32!1/64!1/128!

Page 21: Distributed Hash Tables: Chord - UCL Computer Science

21

Finger i Points to Successor of n+2i

N80"

½"¼"

1/8!

1/16!1/32!1/64!1/128!

112

N120"

Page 22: Distributed Hash Tables: Chord - UCL Computer Science

22

Lookup with Fingers

Lookup(my-id, key-id) look in local finger table for highest node n s.t. my-id < n < key-id if n exists call Lookup(key-id) on node n // next hop else return my successor // done

Page 23: Distributed Hash Tables: Chord - UCL Computer Science

23

Lookups Take O(log(N)) Hops

N32"

N10"

N5"

N20"N110"

N99"

N80"

N60"

Lookup(K19)

K19

Page 24: Distributed Hash Tables: Chord - UCL Computer Science

24

Joining: Linked List Insert

N36"

N40"

N25"

1. Lookup(36) K30 K38

Page 25: Distributed Hash Tables: Chord - UCL Computer Science

25

Join (2)

N36"

N40"

N25"

2. N36 sets its own successor pointer

K30 K38

Page 26: Distributed Hash Tables: Chord - UCL Computer Science

26

Join (3)

N36"

N40"

N25"

3. Copy keys 26..36 from N40 to N36

K30 K38

K30

Page 27: Distributed Hash Tables: Chord - UCL Computer Science

27

Join (4)

N36"

N40"

N25"

4. Set N25’s successor pointer

Predecessor pointer allows link to new host Update finger pointers in the background Correct successors produce correct lookups

K30 K38

K30

Page 28: Distributed Hash Tables: Chord - UCL Computer Science

28

Failures Might Cause Incorrect Lookup

N120"N113"

N102"

N80"

N85"

N80 doesn’t know correct successor, so incorrect lookup

N10"

Lookup(90)

Page 29: Distributed Hash Tables: Chord - UCL Computer Science

29

Solution: Successor Lists

•  Each node knows r immediate successors •  After failure, will know first live successor •  Correct successors guarantee correct lookups

•  Guarantee is with some probability

Page 30: Distributed Hash Tables: Chord - UCL Computer Science

30

Choosing Successor List Length

•  Assume 1/2 of nodes fail •  P(successor list all dead) = (1/2)r

–  i.e., P(this node breaks the Chord ring) – Depends on independent failure

•  P(no broken nodes) = (1 – (1/2)r)N

–  r = 2log(N) makes prob. = 1 – 1/N

Page 31: Distributed Hash Tables: Chord - UCL Computer Science

31

Lookup with Fault Tolerance Lookup(my-id, key-id)

look in local finger table and successor-list for highest node n s.t. my-id < n < key-id if n exists call Lookup(key-id) on node n // next hop if call failed, remove n from finger table return Lookup(my-id, key-id) else return my successor // done

Page 32: Distributed Hash Tables: Chord - UCL Computer Science

32

Experimental Overview

•  Quick lookup in large systems •  Low variation in lookup costs •  Robust despite massive failure

Experiments confirm theoretical results

Page 33: Distributed Hash Tables: Chord - UCL Computer Science

33

Chord Lookup Cost Is O(log N)

Number of Nodes

Aver

age

Mes

sage

s pe

r Lo

okup

Constant is 1/2

Page 34: Distributed Hash Tables: Chord - UCL Computer Science

34

Failure Experimental Setup

•  Start 1,000 CFS/Chord servers – Successor list has 20 entries

•  Wait until they stabilize •  Insert 1,000 key/value pairs

– Five replicas of each

•  Stop X% of the servers •  Immediately perform 1,000 lookups

Page 35: Distributed Hash Tables: Chord - UCL Computer Science

35

DHash Replicates Blocks at r Successors

N40"

N10"N5"

N20"

N110"

N99"

N80"

N60"

N50"

Block 17

N68"

•  Replicas are easy to find if successor fails •  Hashed node IDs ensure independent failure

Page 36: Distributed Hash Tables: Chord - UCL Computer Science

36

Massive Failures Have Little Impact

0

0.2

0.4

0.6

0.8

1

1.2

1.4

5 10 15 20 25 30 35 40 45 50

Faile

d Lo

okup

s (P

erce

nt)

Failed Nodes (Percent)

(1/2)6 is 1.6%

Page 37: Distributed Hash Tables: Chord - UCL Computer Science

37

DHash Properties

•  Builds key/value storage on Chord •  Replicates blocks for availability

– What happens when DHT partitions, then heals? Which (k, v) pairs do I need?

•  Caches blocks for load balance •  Authenticates block contents

Page 38: Distributed Hash Tables: Chord - UCL Computer Science

38

DHash Data Authentication

•  Two types of DHash blocks: – Content-hash: key = SHA-1(data) – Public-key: key is a public key, data are

signed by that key

•  DHash servers verify before accepting •  Clients verify result of get(key)

•  Disadvantages?

Page 39: Distributed Hash Tables: Chord - UCL Computer Science

DHTs: A Retrospective

•  Original DHTs (CAN, Chord, Kademlia, Pastry, Tapestry) proposed in 2001-02

•  Following 5-6 years saw proliferation of DHT-based applications: –  filesystems (e.g., CFS, Ivy, Pond, PAST) –  naming systems (e.g., SFR, Beehive) –  indirection/interposition systems (e.g., i3, DOA) –  content distribution systems (e.g., Coral) –  distributed databases (e.g., PIER) – &c.…

39

Page 40: Distributed Hash Tables: Chord - UCL Computer Science

DHTs: A Retrospective

•  Original DHTs (CAN, Chord, Kademlia, Pastry, Tapestry) proposed in 2001-02

•  Following 5-6 years saw proliferation of DHT-based applications: –  filesystems (e.g., CFS, Ivy, Pond, PAST) –  naming systems (e.g., SFR, Beehive) –  indirection/interposition systems (e.g., i3, DOA) –  content distribution systems (e.g., Coral) –  distributed databases (e.g., PIER) – &c.…

40

Have these applications succeeded—are we all using them today? Have DHTs succeeded as a substrate for applications?

Page 41: Distributed Hash Tables: Chord - UCL Computer Science

What DHTs Got Right

•  Consistent Hashing –  simple, elegant way to divide a workload across

machines –  very useful in clusters: actively used today in

Dynamo, FAWN-KV, ROAR, … •  Replication for high availability, efficient

recovery after node failure •  Incremental scalability: “add nodes, capacity

increases” •  Self-management: minimal configuration

41

Page 42: Distributed Hash Tables: Chord - UCL Computer Science

What DHTs Got Right

•  Consistent Hashing –  simple, elegant way to divide a workload across

machines –  very useful in clusters: actively used today in

Dynamo, FAWN-KV, ROAR, … •  Replication for high availability, efficient

recovery after node failure •  Incremental scalability: “add nodes, capacity

increases” •  Self-management: minimal configuration

42

Unique trait: no single central server to shut dow, control, or monitor …well suited to “illegal” applications, be they sharing music or resisting censorship

Page 43: Distributed Hash Tables: Chord - UCL Computer Science

DHTs’ Limitations

•  High latency between peers •  Limited bandwidth between peers (as

compared to within a cluster) •  Lack of centralized control: another sort of

simplicity of management •  Lack of trust in peers’ correct behavior

– securing DHT routing hard, unsolved in practice

43