Post on 31-Dec-2015
description
SKIP LIST & SKIP GRAPH
James AspnesGauri Shah
Many slides have been taken from the original presentation by the authors
2
Definition of Skip ListA skip list for a set L of distinct (key, element) items is a series of linked lists L0, L1 , … , Lh such that
Each list Li contains the special keys +∞ and -∞List L0 contains the keys of L in non-decreasing order Each list is a subsequence of the previous one, i.e.,
L0 ⊃ L1 ⊃ … ⊃ Lh
List Lh contains only the two special keys +∞ and -∞
3
Skip List
(Idea due to Pugh ’90, CACM paper)Dictionary based on a probabilistic data structure.Allows efficient search, insert, and delete operations.Each element in the dictionary typically stores additionaluseful information beside its search key. Example:
<student id. Transcripts> [for University of Iowa]<date, news> [for Daily Iowan]
Probabilistic alternative to a balanced tree.
4
Skip List
A G J M R W
HEAD TAIL
Each node linked at higher level with probability 1/2.
Level 0
A J M
Level 1
J
Level 2
∞∞
5
Another example
56 64 78 ∞31 34 44∞ 12 23 26
∞31∞
64 ∞31 34∞ 23
L0
L1
L2
Each element of Li appears in L.i+1 with probability p.Higher levels denote express lanes.
6
Searching in Skip List
Search for a key x in a skip:
Start at the first position of the top list At the current position P, compare x with y ≥ key after P
x = y -> return element (after (P))x > y -> “scan forward” x < y -> “drop down”
– If we move past the bottom list, then no such key exists
7
Example of search for 78
∞∞
L1
L2
L3
∞31∞
64 ∞31 34∞ 23
56 64 78 ∞31 34 44∞ 12 23 26L0
At L1 P is the next element ∞ is bigger than 78, we drop downAt L0, 78 = 78, so the search is over.
8
Insertion
• The insert algorithm uses randomization to decide in how many levels the new item <k> should be added to the skip list.
• After inserting the new item at the bottom level flip a coin.
• If it returns tail, insertion is complete. Otherwise, move to next higher level and insert <k> in this level at
the appropriate position, and repeat the coin flip.
9
Insertion Example
∞∞ 10 36
∞∞
23
23 ∞∞
L0
L1
L2
∞∞
L0
L1
L2
L3
∞∞ 10 362315
∞∞ 15
∞∞ 2315p0
p1
p2
1) Suppose we want to insert 152) Do a search, and find the spot between 10 and 233) Suppose the coin come up “head” three times
10
Deletion
• Search for the given key <k>. If a position with key <k> is not found, then no such key exists.
• Otherwise, if a position with key <k> is found (it will be definitely found on the bottom level), then we remove all occurrences of <k> from every level.
• If the uppermost level is empty, remove it.
11
Deletion Example1) Suppose we want to delete 342) Do a search, find the spot between 23 and 453) Remove all occurrences of the key
∞ ∞4512
∞ ∞
23
23∞ ∞
L0
L1
L2
L0
L1
L2
∞ ∞4512 23 34
∞ ∞34
∞ ∞23 34p0
p1
p2
12
O(1) pointers per node
Average number of pointers per node = O(1)
Total number of pointers
= 2.n + 2. n/2 + 2. n/4 + 2. n/8 + … = 4.n
So, the average number of pointers per node = 4
13
Number of levels
Pr[a given element x is above level c log n] = 1/2c log n = 1/nc
Pr[any element is above level c log n] = n. 1/nc
= 1/nc-1
So the number of levels = O(log n) with high probability
The number of levels = O(log n) w.h.p
14
Search time
Consider a skiplist with two levels L0 and L1. To search a key, first search L1 and then search L0.
Cost (i.e. search time) = length (L1) + n / length (L1) Minimum when length (L1) = n / length (L1).
Thus length(L1) = (n) 1/2, and cost = 2. (n) 1/2
(Three lists) minimum cost = 3. (n)1/3
(Log n lists) minimum cost = log n. (n) 1/log n = 2.log n
15
Skip lists for P2P?
• Heavily loaded top-level nodes.• Easily susceptible to failures.• Lacks redundancy.
Disadvantages
Advantages• O(log n) expected search time.• Retains locality.• Dynamic node additions/deletions.
16
A Skip Graph
A001
J001
M011
G100 W101
R110
Level 1
G
R
W
A J M000 001 011
101
110
100Level 2
A G J M R W001 001 011100 110 101Level 0
Membership vectors
Link at level i to nodes with matching prefix of length i.Think of a tree of skip lists that share lower layers.
17
Properties of skip graphs
1. Efficient Searching.2. Efficient node insertions & deletions.3. Independence from system size.4. Locality and range queries.
18
Searching: avg. O (log n)
Same performance as DHTs.
A J MG WR
Leve
l 1
GR
WA J MLe
vel 2
A G J M R W
Leve
l 0
Restricting to the lists containing the starting element of the search, we get a skip list.
19
Node Insertion – 1
A
001
M
011
G
100
W101
R110Le
vel 1
G
R
W
A M
000 011
101
110
100Leve
l 2
A G M R W
001 011100 110 101
Leve
l 0J
001
Starting at buddy node, find nearest key at level 0.Takes O(log n) time on average.
buddy new node
20
Node Insertion - 2At each level i, find nearest node with matching
prefix of membership vector of length i.
A001
M011
G
100
W101
R110Le
vel 1
G
R
W
A M
000 011
101
110
100Leve
l 2
A G M R W
001 011100 110 101Leve
l 0 J
001
J
001
J
001
Total time for insertion: O(log n)DHTs take: O(log2n)
21
Independent of system sizeNo need to know size of keyspace or number of nodes.
E Z1 0
E ZJ
insert
Level 0
Level 1
E Z1 0
E Z
J0
J00 01
E ZJ
Level 0
Level 1
Level 2
Old nodes extend membership vector as required with arrivals.DHTs require knowledge of keyspace size initially.
22
Locality and range queries
• Find key < F, > F.• Find largest key < x.• Find least key > x.
• Find all keys in interval [D..O].
• Initial node insertion at level 0.
D F A I
D F A I L O S
23
Applications of locality
news:02/13
e.g. find latest news from yesterday. find largest key < news: 02/13.
news:02/11 news:02/12news:02/10news:02/09Level 0
DHTs cannot do this easily as hashing destroys locality.
e.g. find any copy of some Britney Spears song.
britney05britney03 britney04britney02britney01Level 0
Data Replication
Version Control
24
So far...
Decentralization.
Locality properties.
O(log n) space per node.
O(log n) search, insert, and delete time.
Independent of system size.
Coming up...
• Load balancing.
•Tolerance to faults.
• Self-stabilization.
• Random faults.• Adversarial faults.
25
Load balancing
Interested in average load on a node u.i.e. the number of searches from source s to destination t that use node u.
Theorem: Let dist (u, t) = d. Then the probability that a search from s to t passes through u is < 2/(d+1).
where V = {nodes v: u <= v <= t} and |V| = d+1.
26
Nodes u
Observation
Level 0
Level 1
Level 2
Node u is on the search path from s to t only if it is inthe skip list formed from the lists of s at each level.
s
27
Tallest nodes
Node u is on the search path from s to t only if it isin T = the set of k tallest nodes in [u..t].
u
u t
s u is not on path.
tu
u
s
u
u is on path.
Pr [u T] = Pr[|T|=k] • k/(d+1) = E[|T|]/(d+1).k=1
d+1
Heights independent of position, so distances are symmetric.
∈
28
Load on node uStart with n nodes. Each node goes to next set with prob. 1/2.We want expected size of T = last non-empty set.
= T
Average load on a node is inversely proportional to the distance from the destination.
We show that: E[|T|] < 2.
Asymptotically: E[|T|] = 1/(ln 2) ± 2x10-5 ≃ 1.4427… [Trie analysis]
29
Expected loadActual loadDestination = 76542
76400 76450 76500 76550 76600 76650
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1.0
1.1
0.0
Node location
Load
on
nod
eExperimental result
30
Fault tolerance
How do node failures affect skip graph performance?
Random failures: Randomly chosen nodes fail. Experimental results.
Adversarial failures: Adversary carefully chooses nodes that fail. Bound on expansion ratio.
31
Random faults
Size of largest connected component
as fraction of live nodes
0.00
0.20
0.40
0.60
0.80
1.00
1.20
0.0
0
0.0
5
0.1
0
0.1
5
0.2
0
0.2
5
0.3
0
0.3
5
0.4
0
0.4
5
0.5
0
0.5
5
0.6
0
0.6
5
0.7
0
0.7
5
0.8
0
0.8
5
0.9
0
0.9
5
Probability of node failure
Siz
e
131072 nodes
32
Searches with random failures
Fraction of f ailed searches
0.00
0.05
0.10
0.15
0.20
0.25
0.0
0.1
0.2
0.3
0.4
0.5
0.6
Probability of node f ailure
Fai
led s
earc
hes 131072 nodes
10000 messages
33
Adversarial faults
Theorem: A skip graph with n nodes has expansion ratio = (1/log n).Ω
A
dA
dA = nodes adjacent to A but not in A. To disconnect A all nodes in dA must be removed
Expansion ratio = min |dA|/|A|, 1 <= |A| <= n/2.
f failures can isolate only O(f•log n ) nodes.
34
Need for repair mechanism
A J MG WR
Level 1
GR
WA J MLe
vel 2
A G J M R W
Level 0
Node failures can leave skip graph in inconsistent state.
35
Ideal skip graph
Let xRi (xLi) be the right (left) neighbor of x at level i.
xLi < x < xRi.xLiRi = xRiLi = x.
Invariant
kxRi = xRi-1.
kxLi = xLi-1. Successor
constraints
x
Level i
Level i-1
ixR
i-1xR1
i-1xR2
x
..00..
..01.. ..00..
If xLi, xRi exist:
36
Basic repairIf a node detects a missing neighbor, it tries
to patch the link using other levels.
1 2 4 5 63
31 5 6
1 5
Also relink at other lower levels.
Successor constraints may be violated by node arrivals or failures.
37
Constraint violationNeighbor at level i not present at level (i-1).
x
x Level i-1
Level i
Level i-1
Level ix
x
zipper..00.. ..01.. ..01.. ..01.. ..00.. ..01.. ..01....01.. ..00.. ..01..
..01.. ..00.. ..01..
x
x..01..
38
Conclusions
• Decentralization.
• O(log n) space at each node.
• O(log n) search time.
• Load balancing properties.
• Tolerant of random faults.
Similarities with DHTs
39
Property DHTs Skip Graphs
Insert/Delete time
O(log2n) O(log n)
Locality No Yes
Repair mechanism
? Partial
Tolerance ofadversarial faults
? Yes
Keyspace size Reqd. Not reqd.
Differences
40
Open Problems
• Evaluate performance in practice.
• Incorporate geographical proximity.
• Study multi-dimensional skip graphs.
• Study effect of byzantine failures.
?
• Design efficient repair mechanism.