A Concurrency-Optimal Binary Search Tree Vitaly Aksenov, INRIA - - PowerPoint PPT Presentation

a concurrency optimal binary search tree
SMART_READER_LITE
LIVE PREVIEW

A Concurrency-Optimal Binary Search Tree Vitaly Aksenov, INRIA - - PowerPoint PPT Presentation

A Concurrency-Optimal Binary Search Tree Vitaly Aksenov, INRIA Paris / ITMO University Vincent Gramoli, University of Sydney Petr Kuznetsov, Telecom ParisTech Anna Malova, Washington University in St.Louis Srivatsan Ravi, University of


slide-1
SLIDE 1

A Concurrency-Optimal Binary Search Tree

Vitaly Aksenov, INRIA Paris / ITMO University Vincent Gramoli, University of Sydney Petr Kuznetsov, Telecom ParisTech Anna Malova, Washington University in St.Louis Srivatsan Ravi, University of Southern California Euro-Par 2017

1 / 67

slide-2
SLIDE 2

Motivation

◮ How to measure efficiency of the data structure?

◮ Practically: performance evaluation. Non-portable,

architecture- and workload- dependent.

◮ Theoretically: lower bounds. Usually worst-case

behaviour, rarely observed in practice.

◮ Concurrency-optimality [Gramoli et al., SIROCCO 2016].

List-based Set [Gramoli et al., DISC 2015].

◮ This paper: a concurrency-optimal binary search tree

exists and performs well.

2 / 67

slide-3
SLIDE 3

Outline

Sequential partially-external BST Concurrent Binary Search Tree Concurrency Optimality Concurrency-optimal BST Evaluation Conclusion

3 / 67

slide-4
SLIDE 4

Outline

Sequential partially-external BST Concurrent Binary Search Tree Concurrency Optimality Concurrency-optimal BST Evaluation Conclusion

4 / 67

slide-5
SLIDE 5

Specification

High-level: Set type.

◮ Insert(x)

◮ true if x does not exists ◮ false if x exist

◮ Delete(x)

◮ true if x exists ◮ false if x does not exist

◮ Contains(x)

◮ true if x exists ◮ false if x does not exist 5 / 67

slide-6
SLIDE 6

Partially-external BST

Data structure: partially-external binary search tree.

◮ Key in the node is greater than

keys in the left subtree and is less than keys in the right subtree.

◮ Two types of nodes: DATA

(white) or ROUTING (grey).

◮ Invariant: ROUTING nodes

always have two children.

◮ Set consists of keys in DATA

nodes. 6 4 5 2 1 8 {1, 2, 5, 6, 8}

6 / 67

slide-7
SLIDE 7

Traverse

At the beginning of the operation we traverse a tree starting from the root to find a node with x to delete or a position to insert x:

◮ If the key in the current node is greater than x then go to

the left subtree.

◮ If the key in the current node is less than x then go to

the right subtree.

◮ If the key in the current node equals to x or the node is a

leaf then stop.

7 / 67

slide-8
SLIDE 8
  • Sequential. Insert leaf. Insert(3)

2 null

8 / 67

slide-9
SLIDE 9
  • Sequential. Insert leaf. Insert(3)

2 3

9 / 67

slide-10
SLIDE 10
  • Sequential. Insert ROUTING. Insert(2)

2

10 / 67

slide-11
SLIDE 11
  • Sequential. Insert ROUTING. Insert(2)

2

11 / 67

slide-12
SLIDE 12
  • Sequential. Delete node with two children.

Delete(2)

2

12 / 67

slide-13
SLIDE 13
  • Sequential. Delete node with two children.

Delete(2)

2

13 / 67

slide-14
SLIDE 14
  • Sequential. Delete node with one child. Delete(2)

6 2

14 / 67

slide-15
SLIDE 15
  • Sequential. Delete node with one child. Delete(2)

6

15 / 67

slide-16
SLIDE 16
  • Sequential. Delete leaf with DATA parent.

Delete(3)

2 3

16 / 67

slide-17
SLIDE 17
  • Sequential. Delete leaf with DATA parent.

Delete(3)

2 null

17 / 67

slide-18
SLIDE 18
  • Sequential. Delete leaf with ROUTING parent.

Delete(3)

6 2 3

18 / 67

slide-19
SLIDE 19
  • Sequential. Delete leaf with ROUTING parent.

Delete(3)

6

19 / 67

slide-20
SLIDE 20

Outline

Sequential partially-external BST Concurrent Binary Search Tree Concurrency Optimality Concurrency-optimal BST Evaluation Conclusion

20 / 67

slide-21
SLIDE 21

Concurrent BST

◮ Supports Insert, Delete and Contains. ◮ BST structure and invariants. ◮ Linearizability [Herlihy et al., TOPLAS 1990] with respect

to Set type.

◮ State-of-the-art concurrent BSTs: [Bronson et al.,

PPoPP 2010], [Ellen et al., PODC 2010], [Crain et al., Euro-Par 2013], [Drachsler et al., PPoPP 2014], [Natarajan et al., PPoPP 2014].

21 / 67

slide-22
SLIDE 22

Outline

Sequential partially-external BST Concurrent Binary Search Tree Concurrency Optimality Concurrency-optimal BST Evaluation Conclusion

22 / 67

slide-23
SLIDE 23

Non-linearizable schedule

◮ Consider for a moment that we run sequential

implementation in a concurrent environment.

◮ Schedule is an execution of the sequential algorithm in

concurrent environment p inserts 3 and q inserts 4. They traverse the tree and are ready to insert a leaf. 5 2 null 3 4 p q

23 / 67

slide-24
SLIDE 24

Non-linearizable schedule

p sets the leaf link to 3. 5 2 3 4 p q

24 / 67

slide-25
SLIDE 25

Non-linearizable schedule

q overwrites the link. Insert(3) is lost: Contains(3) returns false. 5 2 3 4 p q

25 / 67

slide-26
SLIDE 26

Non-linearizable schedule

insert(3) insert(4) contains(3) p q true true ?false

26 / 67

slide-27
SLIDE 27

Schedules

◮ Schedule is accepted if some execution of a concurrent

implementation contains it as a subsequence.

◮ Not all schedules should be accepted. (As the presented

  • ne)

◮ Observably correct schedules: the prefixes of the

schedule are linearizable and the shared data structure is a BST.

27 / 67

slide-28
SLIDE 28

Definition

An implementation is concurrency-optimal if it accepts all

  • bservably correct schedules and only observably correct

schedules. Intuitively: a concurrency-optimal BST employs as much synchronization as necessary for high-level correctness.

28 / 67

slide-29
SLIDE 29

Interesting schedule

To illustrate the difficulty of designing a concurrency-optimal BST consider the following schedule. p invokes Delete(3), traverses to node 3 and falls asleep. 2 3 p

delete(3) p q

29 / 67

slide-30
SLIDE 30

Interesting schedule

q invokes Delete(3), traverses to node 3, unlinks it and returns. 2 3 p null

delete(3) delete(3) p q

30 / 67

slide-31
SLIDE 31

Interesting schedule

q invokes Insert(3), links a new node 3 to node 2 and returns. 2 3 p 3

delete(3) delete(3) insert(3) p q

31 / 67

slide-32
SLIDE 32

Interesting schedule

p wakes up and unlinks the new node from the tree. 2 3 p null

delete(3) delete(3) insert(3) p q

32 / 67

slide-33
SLIDE 33

Interesting schedule

◮ This schedule is observably correct. ◮ But it is not accepted by partially-external BSTs [Bronson

et al., PPoPP 2010] and [Crain et al., Euro-Par 2013].

◮ External BSTs ([Ellen et al., PODC 2010], [Natarajan et

al., PPoPP 2014]) and internal BST ([Drachsler et al., PPoPP 2014]) do not accept similar schedule.

33 / 67

slide-34
SLIDE 34

Outline

Sequential partially-external BST Concurrent Binary Search Tree Concurrency Optimality Concurrency-optimal BST Evaluation Conclusion

34 / 67

slide-35
SLIDE 35

Optimal implementation

◮ We perform everything optimistically: traverse, load all

the necessary nodes and fields, such as state, choose the case.

◮ Right before the modification we take a lock on

everything and check all the necessary conditions:

◮ link is still present; ◮ link goes to the node with the proper value; ◮ proper state: DATA or ROUTING; ◮ node is not removed, i.e., deleted mark is not set; ◮ proper number of children. 35 / 67

slide-36
SLIDE 36

Optimal implementation

◮ The critical section consists of one line of sequential

implementation together with “wrapping block”.

◮ Could be interleaved in any way if the conditions are

satisfied.

◮ The conditions are satisfied if and only if the schedule is

  • bservably correct.

◮ Such an implementation is concurrency-optimal.

36 / 67

slide-37
SLIDE 37

Additional optimizations.

◮ Can be optimized further. ◮ Accept more interleavings of the concurrent

implementation.

◮ Three locks: state, left and right children ([Natarajan et

al., PPoPP 2014]);

◮ Read/write locks. 37 / 67

slide-38
SLIDE 38

Implementation

◮ Now, look into more details which locks are taken and

which checks are performed in different cases.

◮ Assume that an update operation already traversed, read

all the nodes and fields and chose the case.

38 / 67

slide-39
SLIDE 39
  • Implementation. Insert leaf. Insert(3).

2

  • 1. lock right edge

compare with null null

39 / 67

slide-40
SLIDE 40
  • Implementation. Insert leaf. Insert(3).

2

  • 1. lock right edge

compare with null

  • 2. lock state

not deleted null

40 / 67

slide-41
SLIDE 41
  • Implementation. Insert leaf. Insert(3).

2 3

41 / 67

slide-42
SLIDE 42
  • Implementation. Insert ROUTING. Insert(2).

2 lock state state == ROUTING not deleted

42 / 67

slide-43
SLIDE 43
  • Implementation. Insert ROUTING. Insert(2).

2

43 / 67

slide-44
SLIDE 44

Delete node with two children. Delete(2)

2 lock state state == DATA not deleted check for 2 children

44 / 67

slide-45
SLIDE 45

Delete node with two children. Delete(2)

2

45 / 67

slide-46
SLIDE 46

Delete node with one child. Delete(2)

6

  • 1. lock right edge

check reference 2

46 / 67

slide-47
SLIDE 47

Delete node with one child. Delete(2)

6

  • 1. lock right edge

check reference

  • 2. lock left edge

check reference 2

47 / 67

slide-48
SLIDE 48

Delete node with one child. Delete(2)

6

  • 1. lock right edge

check reference

  • 2. lock left edge

check reference

  • 3. lock state

state == DATA not deleted check for 1 child 2

48 / 67

slide-49
SLIDE 49

Delete node with one child. Delete(2)

6

49 / 67

slide-50
SLIDE 50

Delete leaf with DATA parent. Delete(3)

2 3

  • 1. lock right edge

check value

50 / 67

slide-51
SLIDE 51

Delete leaf with DATA parent. Delete(3)

2 3

  • 1. lock right edge

check value

  • 2. lock state

not deleted check for leaf

51 / 67

slide-52
SLIDE 52

Delete leaf with DATA parent. Delete(3)

2 3

  • 1. lock right edge

check value

  • 2. lock state

not deleted check for leaf

  • 3. lock state

state == DATA not deleted

52 / 67

slide-53
SLIDE 53

Delete leaf with DATA parent. Delete(3)

2 null

53 / 67

slide-54
SLIDE 54

Delete leaf with ROUTING parent. Delete(3)

6 2 3

  • 1. lock right edge

check value

54 / 67

slide-55
SLIDE 55

Delete leaf with ROUTING parent. Delete(3)

6 2 3

  • 1. lock right edge

check value

  • 2. lock state

not deleted check for leaf

55 / 67

slide-56
SLIDE 56

Delete leaf with ROUTING parent. Delete(3)

6 2 3

  • 1. lock right edge

check value

  • 2. lock state

not deleted check for leaf

  • 3. lock left edge

check reference

56 / 67

slide-57
SLIDE 57

Delete leaf with ROUTING parent. Delete(3)

6 2 3

  • 1. lock right edge

check value

  • 2. lock state

not deleted check for leaf

  • 3. lock left edge

check reference

  • 4. lock left edge

check reference

57 / 67

slide-58
SLIDE 58

Delete leaf with ROUTING parent. Delete(3)

6 2 3

  • 1. lock right edge

check value

  • 2. lock state

not deleted check for leaf

  • 3. lock left edge

check reference

  • 4. lock left edge

check reference

  • 5. lock state

state == ROUTING not deleted

58 / 67

slide-59
SLIDE 59

Delete leaf with ROUTING parent. Delete(3)

6

59 / 67

slide-60
SLIDE 60

Outline

Sequential partially-external BST Concurrent Binary Search Tree Concurrency Optimality Concurrency-optimal BST Evaluation Conclusion

60 / 67

slide-61
SLIDE 61

Settings

◮ 80-way Intel machine and 64-way AMD machine. ◮ Update ratio x: 0, 20, 100.

x 2% insert,

x 2% delete,

◮ 100 − x% contains.

◮ Value range: 215, 219 and 221. ◮ The tree is prepopulated with range/2 values. ◮ Metric: throughput (operations per second).

61 / 67

slide-62
SLIDE 62

Algorithms

◮ Concurrency Friendly, [Crain et al., Euro-Par 2013]; ◮ Logical Ordering, [Drachsler et al., PPoPP 2014]; ◮ BCCO, [Bronson et al., PPoPP 2010]; ◮ EFRB, [Ellen et al., PODC 2010].

62 / 67

slide-63
SLIDE 63

Intel machine

20 40 60 80 20 40 60 Range: 221 Update rate: 0% 20 40 60 80 20 40 Number of threads Update rate: 20% 20 40 60 80 20 40 Update rate: 100% Concurrency Optimal Concurrency Friendly Logical Ordering BCCO EFRB

63 / 67

slide-64
SLIDE 64

AMD machine

20 40 60 5 10 15 Range: 221 Update rate: 0% 20 40 60 5 10 15 Number of threads Update rate: 20% 20 40 60 5 10 15 Update rate: 100% Concurrency Optimal Concurrency Friendly Logical Ordering BCCO EFRB

64 / 67

slide-65
SLIDE 65

Outline

Sequential partially-external BST Concurrent Binary Search Tree Concurrency Optimality Concurrency-optimal BST Evaluation Conclusion

65 / 67

slide-66
SLIDE 66

Conclusion

◮ Provably concurrency-optimal algorithm may perform well

in practice.

◮ Concurrency-optimality could be an adequate design

principle for efficient concurrent data structures. Besides BST, Linked List based Set [Gramoli et al., DISC 2015].

◮ Which other data structures could be optimized using this

approach? What are the limitations?

66 / 67

slide-67
SLIDE 67

Questions

Thank you for attention!

67 / 67