optimizing linearizable bulk operations on data structures · elemental operation 16 aggressive...

36
Optimizing Linearizable Bulk Operations on Data Structures Authors: Matthew Rodriguez, Michael Spear

Upload: others

Post on 12-Oct-2020

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Optimizing Linearizable Bulk Operations on Data Structures · Elemental Operation 16 Aggressive Ordering Get ID of last linearized bulk op, lastLinID lastLinIDrepresents earliest

Optimizing Linearizable

Bulk Operations on

Data Structures

Authors:

Matthew Rodriguez,

Michael Spear

Page 2: Optimizing Linearizable Bulk Operations on Data Structures · Elemental Operation 16 Aggressive Ordering Get ID of last linearized bulk op, lastLinID lastLinIDrepresents earliest

Introduction

2

Optimizing Linearizable Bulk Operations on Data Structures

Page 3: Optimizing Linearizable Bulk Operations on Data Structures · Elemental Operation 16 Aggressive Ordering Get ID of last linearized bulk op, lastLinID lastLinIDrepresents earliest

Background

3

Introduction

● Concurrent data structures are important, but hard to design

● Bulk operations pose significant scaling challenge

● Simplest solution is two-phase locking (2PL)

Page 4: Optimizing Linearizable Bulk Operations on Data Structures · Elemental Operation 16 Aggressive Ordering Get ID of last linearized bulk op, lastLinID lastLinIDrepresents earliest

Prior Work

4

Introduction

● Atomic snapshot

○ Time and memory cost

○ Staleness

○ Read-only

● Multi-versioning

○ Memory cost

○ Staleness

○ Read-only

Page 5: Optimizing Linearizable Bulk Operations on Data Structures · Elemental Operation 16 Aggressive Ordering Get ID of last linearized bulk op, lastLinID lastLinIDrepresents earliest

Our Contribution

5

Introduction

● Propose three algorithms for maps

● Support linearizable bulk operations

○ Entire bulk operation, end-to-end, is linearizable

● Linearizability

○ Strong correctness condition

○ Must exist an equivalent sequential ordering

○ Must obey real-time order

● Meet several additional design constraints

Page 6: Optimizing Linearizable Bulk Operations on Data Structures · Elemental Operation 16 Aggressive Ordering Get ID of last linearized bulk op, lastLinID lastLinIDrepresents earliest

Design Constraints

6

Introduction

● Focus on system software

● Strict memory bounds

● No leaks, no garbage collector

● Support mutating bulk operations

● Support bulk ops with loop-carried data dependencies

● Generic algorithms applicable to multiple data structures

Page 7: Optimizing Linearizable Bulk Operations on Data Structures · Elemental Operation 16 Aggressive Ordering Get ID of last linearized bulk op, lastLinID lastLinIDrepresents earliest

Motivation

7

Introduction

● Primary underlying question: delay when?

● Answer this question using metadata

● Differ in location and granularity of metadata

Page 8: Optimizing Linearizable Bulk Operations on Data Structures · Elemental Operation 16 Aggressive Ordering Get ID of last linearized bulk op, lastLinID lastLinIDrepresents earliest

Metadata Granularity

8

Introduction

● Low granularity

○ Lack of information

● High granularity

○ More overhead

Page 9: Optimizing Linearizable Bulk Operations on Data Structures · Elemental Operation 16 Aggressive Ordering Get ID of last linearized bulk op, lastLinID lastLinIDrepresents earliest

Metadata Location

9

Introduction

● Global vs local metadata

● Global

○ Greater risk of contention

● Local

○ More overhead

○ Each thread has access to less metadata

○ Metadata granularity controlled by number of partitions

Page 10: Optimizing Linearizable Bulk Operations on Data Structures · Elemental Operation 16 Aggressive Ordering Get ID of last linearized bulk op, lastLinID lastLinIDrepresents earliest

Cycle Example

10

Introduction

● Thread E performs elementals ω1, ω2

● Thread F performs foreach operation ωF

● Due to order of accesses to e1, ωF → ω1

● Due to order of accesses to e3, ω2 → ωF

● Due to temporal order by same thread, ω1 → ω2

● ω1 → ω2 → ωF → ω1 ... A cycle.

● At least one op must delay to prevent this

Page 11: Optimizing Linearizable Bulk Operations on Data Structures · Elemental Operation 16 Aggressive Ordering Get ID of last linearized bulk op, lastLinID lastLinIDrepresents earliest

Insight

11

Challenges

● The cycle occurred due to Thread E going from left to right

● Going from right to left does not cause a cycle

● ωF linearizes when Thread E goes from right to left

● Track bulk ops’ linearization points

Page 12: Optimizing Linearizable Bulk Operations on Data Structures · Elemental Operation 16 Aggressive Ordering Get ID of last linearized bulk op, lastLinID lastLinIDrepresents earliest

Algorithm 1:

Aggressive Ordering

12

Optimizing Linearizable Bulk Operations on Data Structures

Page 13: Optimizing Linearizable Bulk Operations on Data Structures · Elemental Operation 16 Aggressive Ordering Get ID of last linearized bulk op, lastLinID lastLinIDrepresents earliest

Overview

13

Aggressive Ordering

● Uses coarse-grained, global metadata

● Simple algorithm with low overhead

● Assigns total global order to all bulk ops

● Bulk ops ordered by ID

● Bulk op IDs are assigned by creation time

● Bulk ops that start later always ordered later

Page 14: Optimizing Linearizable Bulk Operations on Data Structures · Elemental Operation 16 Aggressive Ordering Get ID of last linearized bulk op, lastLinID lastLinIDrepresents earliest

Metadata

14

Aggressive Ordering

● lastID used to generate bulk op IDs

● linearizedID used to track which ops have linearized

● Each partition tracks lastVisitorID

Type AOGlobalMetadatalastID : Atomic<Integer64>linearizedID : Atomic<Integer64>

Type AOPartitionLock extends Atomic<Integer64>lastVisitorID : Bit[63]lockBit : Bit

Page 15: Optimizing Linearizable Bulk Operations on Data Structures · Elemental Operation 16 Aggressive Ordering Get ID of last linearized bulk op, lastLinID lastLinIDrepresents earliest

Bulk Operation

15

Aggressive Ordering

● Obtain a unique ID, myID

● Iterate over each partition:

○ Wait until lastVisitorID == myID – 1

○ Lock the partition, do the work, unlock

○ Set lastVisitorID = myID

● Atomically increase linearizedID to myID

Page 16: Optimizing Linearizable Bulk Operations on Data Structures · Elemental Operation 16 Aggressive Ordering Get ID of last linearized bulk op, lastLinID lastLinIDrepresents earliest

Elemental Operation

16

Aggressive Ordering

● Get ID of last linearized bulk op, lastLinID

○ lastLinID represents earliest lin. point, not necessarily the actual lin. Point

● Find partition p containing sought key

● Wait until p.lastVisitorID >= lastLinID

● Lock, do the work, unlock

● Atomically increase linearizedID

○ Set it to value p.lastVisitorID had while locked

Page 17: Optimizing Linearizable Bulk Operations on Data Structures · Elemental Operation 16 Aggressive Ordering Get ID of last linearized bulk op, lastLinID lastLinIDrepresents earliest

Drawbacks

17

Aggressive Ordering

● Unnecessary ordering

○ Disjoint range operations, read-only bulk operations

● Range ops must touch every partition (lastVisitorID)

● Ordering by start time not always best

Page 18: Optimizing Linearizable Bulk Operations on Data Structures · Elemental Operation 16 Aggressive Ordering Get ID of last linearized bulk op, lastLinID lastLinIDrepresents earliest

Algorithm 2:

Dynamic Ordering

18

Optimizing Linearizable Bulk Operations on Data Structures

Page 19: Optimizing Linearizable Bulk Operations on Data Structures · Elemental Operation 16 Aggressive Ordering Get ID of last linearized bulk op, lastLinID lastLinIDrepresents earliest

Overview

19

Dynamic Ordering

● Uses fine-grained, global metadata

● Seeks to address shortcomings in AO with more metadata

Page 20: Optimizing Linearizable Bulk Operations on Data Structures · Elemental Operation 16 Aggressive Ordering Get ID of last linearized bulk op, lastLinID lastLinIDrepresents earliest

Metadata

20

Dynamic Ordering

● The global metadata consists of a list of sets of

BulkOpMetadata objects

● BulkOpMetadata stores metadata on a single bulk op

● Bulk ops in the same set are unordered wrt each other

● Bulk ops in different sets are ordered by position in list

○ Closer to head = ordered earlier, vice versa

Type DOGlobalMetadatabulkOps : List<Set<BulkOpMetadata>>

Type BulkOpMetadataconst startKey : Key const endKey : Keyconst readOnly : BooleanlastKey : Keylinearized : Boolean

Page 21: Optimizing Linearizable Bulk Operations on Data Structures · Elemental Operation 16 Aggressive Ordering Get ID of last linearized bulk op, lastLinID lastLinIDrepresents earliest

Bulk Operation

21

Dynamic Ordering

● Initialize BulkOpMetadata object for op

● Insert BulkOpMetadata into global list as early as possible

● Iterate over each partition:

○ Atomically: search global list for any ops that block this op, and acquire lock on partition

○ Do work, release lock

● Recursively mark this op linearized

● Remove BulkOpMetadata object from global list

Page 22: Optimizing Linearizable Bulk Operations on Data Structures · Elemental Operation 16 Aggressive Ordering Get ID of last linearized bulk op, lastLinID lastLinIDrepresents earliest

Elemental Operation

22

Dynamic Ordering

● Atomically calculate a list of all preceding bulk ops

● Determine which partition p contains the sought key

● Wait until all bulk ops on list are done with k

● Acquire partition lock, perform elemental operation

● Linearize any bulk ops which have accessed k

● Release partition lock

Page 23: Optimizing Linearizable Bulk Operations on Data Structures · Elemental Operation 16 Aggressive Ordering Get ID of last linearized bulk op, lastLinID lastLinIDrepresents earliest

Pros & Cons

23

Dynamic Ordering

● Avoids much of the false waiting incurred by Aggressive Ordering

● Increased overhead

● Contention on global metadata

● Accesses to global metadata are frequent and complex

Page 24: Optimizing Linearizable Bulk Operations on Data Structures · Elemental Operation 16 Aggressive Ordering Get ID of last linearized bulk op, lastLinID lastLinIDrepresents earliest

Algorithm 3:

Localized Ordering

24

Optimizing Linearizable Bulk Operations on Data Structures

Page 25: Optimizing Linearizable Bulk Operations on Data Structures · Elemental Operation 16 Aggressive Ordering Get ID of last linearized bulk op, lastLinID lastLinIDrepresents earliest

Overview

25

Localized Ordering

● Uses fine-grained, local metadata

● Maintains advantages of 2PL (range operations) and builds from there

● 2PL achieves linearizability by delaying operations from starting

● However, it is sufficient to delay them from returning

Page 26: Optimizing Linearizable Bulk Operations on Data Structures · Elemental Operation 16 Aggressive Ordering Get ID of last linearized bulk op, lastLinID lastLinIDrepresents earliest

Metadata

26

Localized Ordering

● No global metadata

● Per-partition metadata consists of two queues

● Any operation must reach head of started queue to access object

● Any operation must reach head of completed queue to return

● completed queue increases concurrency without sacrificing correctness

Type OLPartitionLockstarted : AtomicQueue<ThreadID>completed : AtomicQueue<ThreadID>

Page 27: Optimizing Linearizable Bulk Operations on Data Structures · Elemental Operation 16 Aggressive Ordering Get ID of last linearized bulk op, lastLinID lastLinIDrepresents earliest

Bulk Operation

27

Localized Ordering

● For each partition p:

○ Enqueue in p.started○ Dequeue self from started for previous partition (if exists)

○ Wait until head of p.started○ Operate on p○ Enqueue in p.completed

● Dequeue from last started queue

● Dequeue from all completed queues

Page 28: Optimizing Linearizable Bulk Operations on Data Structures · Elemental Operation 16 Aggressive Ordering Get ID of last linearized bulk op, lastLinID lastLinIDrepresents earliest

Elemental Operation

28

Localized Ordering

● Determine the partition p containing the sought key

● Enqueue in p.started queue

● Wait until head of p.started

● Do work

● Enqueue in p.finished

● Dequeue from p.started

● Wait until head of p.finished

● Dequeue from p.finished

Page 29: Optimizing Linearizable Bulk Operations on Data Structures · Elemental Operation 16 Aggressive Ordering Get ID of last linearized bulk op, lastLinID lastLinIDrepresents earliest

Evaluation

29

Optimizing Linearizable Bulk Operations on Data Structures

Page 30: Optimizing Linearizable Bulk Operations on Data Structures · Elemental Operation 16 Aggressive Ordering Get ID of last linearized bulk op, lastLinID lastLinIDrepresents earliest

Overview

30

Evaluation

● Compare AO, DO, and LO on two data structures

● Chunked skip list of our own design

○ Ordered

● Interlocked Hash Table (IHT)

○ Unordered; therefore, no range ops

● Baseline: Two-Phase Locking

● Upper bound: an implementation where bulk operations are not linearizable (NL)

Page 31: Optimizing Linearizable Bulk Operations on Data Structures · Elemental Operation 16 Aggressive Ordering Get ID of last linearized bulk op, lastLinID lastLinIDrepresents earliest

Foreach-Only Workload

31

Evaluation

Skip List IHT

Page 32: Optimizing Linearizable Bulk Operations on Data Structures · Elemental Operation 16 Aggressive Ordering Get ID of last linearized bulk op, lastLinID lastLinIDrepresents earliest

Range-Only Workload

32

Evaluation

Range Length 4,096 Range Length 131,072

Page 33: Optimizing Linearizable Bulk Operations on Data Structures · Elemental Operation 16 Aggressive Ordering Get ID of last linearized bulk op, lastLinID lastLinIDrepresents earliest

Mixed Workload

33

Evaluation

1 Foreach Thread 2 Range Threads, Length 131,072

Page 34: Optimizing Linearizable Bulk Operations on Data Structures · Elemental Operation 16 Aggressive Ordering Get ID of last linearized bulk op, lastLinID lastLinIDrepresents earliest

Conclusion

34

Optimizing Linearizable Bulk Operations on Data Structures

Page 35: Optimizing Linearizable Bulk Operations on Data Structures · Elemental Operation 16 Aggressive Ordering Get ID of last linearized bulk op, lastLinID lastLinIDrepresents earliest

Conclusion

35

Conclusion

● We introduce three algorithms for scalable linearizable bulk ops

● Performance exceeds 2PL

● Each algorithm has a niche; no single one is best

● Please see the paper for discussion about partition size

Page 36: Optimizing Linearizable Bulk Operations on Data Structures · Elemental Operation 16 Aggressive Ordering Get ID of last linearized bulk op, lastLinID lastLinIDrepresents earliest

Thank you