Fast Multi-Level Locks for Java Khilan Gudka Imperial College - - PowerPoint PPT Presentation

fast multi level locks for java
SMART_READER_LITE
LIVE PREVIEW

Fast Multi-Level Locks for Java Khilan Gudka Imperial College - - PowerPoint PPT Presentation

Fast Multi-Level Locks for Java Khilan Gudka Imperial College London Supervised by Susan Eisenbach Sophia Drossopoulou Tuesday, 20 July 2010 Hierarchical Data Structures Databases - tables, rows, cells Trees - subtree, leaf Hashtables -


slide-1
SLIDE 1

Fast Multi-Level Locks for Java

Khilan Gudka Imperial College London Supervised by Susan Eisenbach Sophia Drossopoulou

Tuesday, 20 July 2010

slide-2
SLIDE 2

Hierarchical Data Structures

Databases - tables, rows, cells Trees - subtree, leaf Hashtables - table, chain, entries

Tuesday, 20 July 2010

slide-3
SLIDE 3

Accesses

Operations may access differing amounts of data e.g. Tree - access individual leaf nodes vs. all nodes in subtree

“lots of data” “little data” c

Tuesday, 20 July 2010

slide-4
SLIDE 4

Accesses

Operations may access differing amounts of data e.g. Tree - access individual leaf nodes vs. all nodes in subtree

“lots of data” “little data” c coarse fine

Tuesday, 20 July 2010

slide-5
SLIDE 5

Concurrent Accesses => Concurrency Control

Lock data before accessing Lock granularity - how much data a lock protects Trade off between concurrency and overhead fine-grained - more concurrency, higher

  • verhead for coarse accesses

coarse-grained - lower overhead, less concurrency for fine accesses

Tuesday, 20 July 2010

slide-6
SLIDE 6

Hierarchical Bank Account Example

Operations on: Account Branch Whole bank

b1 a1 a2 a3 b2 a4 a5 a6 H

Tuesday, 20 July 2010

slide-7
SLIDE 7

Hierarchical Bank Account Example

Operations on: Account Branch Whole bank

b1 a1 a2 a3 b2 a4 a5 a6 H

Tuesday, 20 July 2010

slide-8
SLIDE 8

Fine-Grained Accesses

b1 a1 a2 b2 a4 a5 a6

Operations on: Account Branch Whole bank

H a3

Tuesday, 20 July 2010

slide-9
SLIDE 9

Fine-Grained Accesses

b1 a1 a2 b2 a4 a5 a6

Operations on: Account Branch Whole bank

H

Fine-grained locking => more concurrency

a3

Tuesday, 20 July 2010

slide-10
SLIDE 10

Fine-Grained Accesses

b1 a1 a2 a3 b2 a4 a5 a6

Operations on: Account Branch Whole bank

H

Fine-grained locking => more concurrency

Tuesday, 20 July 2010

slide-11
SLIDE 11

Fine-Grained Accesses

b1 a1 a2 a3 b2 a4 a5 a6

Operations on: Account Branch Whole bank

H

Coarse-grained locking => less concurrency

Tuesday, 20 July 2010

slide-12
SLIDE 12

Fine-Grained Accesses

b1 a1 a2 a3 b2 a4 a5 a6

Operations on: Account Branch Whole bank

H

Coarse-grained locking => less concurrency

Tuesday, 20 July 2010

slide-13
SLIDE 13

Coarse-Grained Accesses

b1 a1 a2 a3 b2 a4 a5 a6

Operations on: Account Branch Whole bank

H

Tuesday, 20 July 2010

slide-14
SLIDE 14

Coarse-Grained Accesses

b1 a1 a2 a3 b2 a4 a5 a6

Operations on: Account Branch Whole bank

H

4 locks Fine-grained locking => more overhead

Tuesday, 20 July 2010

slide-15
SLIDE 15

Coarse-Grained Accesses

b1 a1 a2 a3 b2 a4 a5 a6

Operations on: Account Branch Whole bank

H

1 lock Coarse-grained locking => less overhead

Tuesday, 20 July 2010

slide-16
SLIDE 16

Best of Both Worlds

Workloads access varying amounts of data throughout program’ s lifetime Fine-grained locking when accessing small amounts of data => More concurrency Coarse-grained locking when accessing large amounts of data => Low overhead

Tuesday, 20 July 2010

slide-17
SLIDE 17

Multi-Granularity Locks

Gray et al - “Granularity of Locks in a Shared Data Base” Simultaneous locking at differing granularities Both coarse-grained and fine-grained locks can be used Multi-granularity protocol takes care of their interaction

Tuesday, 20 July 2010

slide-18
SLIDE 18

Multi-Granularity Locks

b1 a1 a2 a3 b2 a4 a5 a6

Operations on: Account Branch Whole bank

H

Individual account accesses => fine-grained locks

Tuesday, 20 July 2010

slide-19
SLIDE 19

Multi-Granularity Locks

b1 a1 a2 a3 b2 a4 a5 a6

Operations on: Account Branch Whole bank

H

Individual account accesses => fine-grained locks

Tuesday, 20 July 2010

slide-20
SLIDE 20

Multi-Granularity Locks

b1 a1 a2 a3 b2 a4 a5 a6

Operations on: Account Branch Whole bank

H

Entire branch access => coarse-grained locks

Tuesday, 20 July 2010

slide-21
SLIDE 21

Multi-Granularity Locks

b1 a1 a2 a3 b2 a4 a5 a6

Operations on: Account Branch Whole bank

H

Interaction between coarse- and fine-grained locks Thread wishes to access a5 => has to wait for b2

Tuesday, 20 July 2010

slide-22
SLIDE 22

Multi-Granularity Locks

b1 a1 a2 a3 b2 a4 a5 a6

Operations on: Account Branch Whole bank

H

Interaction between coarse- and fine-grained locks

Tuesday, 20 July 2010

slide-23
SLIDE 23

Multi-Granularity Locks

Account can be locked if branch is not already locked and vice-versa Interaction is achieved using “intentional mode” locking

Tuesday, 20 July 2010

slide-24
SLIDE 24

Intentional Mode Locking

Before locking a node, lock all ancestors in intentional mode “Locking is being performed lower down, is it

  • k to proceed?”

Tuesday, 20 July 2010

slide-25
SLIDE 25

b1 a1 a2 a3 b2 a4 a5 a6 H

To lock a5, first intentionally acquire H and b2

Intentional Mode Locking

Tuesday, 20 July 2010

slide-26
SLIDE 26

b1 a1 a2 a3 b2 a4 a5 a6 H

To lock a5, first intentionally acquire H and b2

Intentional Mode Locking

Tuesday, 20 July 2010

slide-27
SLIDE 27

b1 a1 a2 a3 b2 a4 a5 a6 H

To lock a5, first intentionally acquire H and b2

Intentional Mode Locking

Tuesday, 20 July 2010

slide-28
SLIDE 28

b1 a1 a2 a3 b2 a4 a5 a6 H

To lock a5, first intentionally acquire H and b2

Intentional Mode Locking

Tuesday, 20 July 2010

slide-29
SLIDE 29

b1 a1 a2 a3 b2 a4 a5 a6 H

To lock a5, first intentionally acquire H and b2

Intentional Mode Locking

Tuesday, 20 July 2010

slide-30
SLIDE 30

Implementation

Used Doug Lea’ s Synchronizer framework in Java 6 - highly performant Lock state represented using 64-bit long All state updates performed using CAS Queues are non-blocking

Tuesday, 20 July 2010

slide-31
SLIDE 31

Performance Evaluation

Does multi-granularity locking actually give a performance benefit? For which workloads does multi-granularity locking perform well?

Tuesday, 20 July 2010

slide-32
SLIDE 32

Micro-benchmark

Hierarchical bank account model with 10 branches each with 10 accounts 1 to 16 threads each perform 1,000,000

  • perations that could be any of the following:
  • 1. Withdraw from random account
  • 2. Deposit into random account
  • 3. Sum balances across random branch
  • 4. Sum balances across whole bank

Tuesday, 20 July 2010

slide-33
SLIDE 33

Micro-benchmark

3 experiments - vary % of each op and measure overall number of ops per sec Compare against ReentrantReadWriteLock and Deuce STM (LSA and TL2 algorithms)

Tuesday, 20 July 2010

slide-34
SLIDE 34

Experiment 1: Fine-Grained

50% withdrawals and 50% deposits

1000 2000 3000 4000 5000 6000 7000 8000 9000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Throughput (Kops/sec) Number of threads Multi-Level Locks Read/Write Locks STM-TL2 STM-LSA

Tuesday, 20 July 2010

slide-35
SLIDE 35

Experiment 2: Medium-Grained

40% with., 40% dep., 10% branch, 10% bank

500 1000 1500 2000 2500 3000 3500 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Throughput (Kops/sec) Number of threads Multi-Level Locks Read/Write Locks STM-TL2 STM-LSA

Tuesday, 20 July 2010

slide-36
SLIDE 36

Experiment 3: Coarse-Grained

20% with., 20% dep., 30% branch, 30% bank

500 1000 1500 2000 2500 3000 3500 4000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Throughput (Kops/sec) Number of threads Multi-Level Locks Read/Write Locks STM-TL2 STM-LSA

Tuesday, 20 July 2010

slide-37
SLIDE 37

Conclusion

Fine-grained locking good for small accesses, coarse-grained locking good for large accesses Multi-granularity allows different granularities

  • f locks simultaneously

Results show that multi-level locks can yield better performance for workloads with a mix

  • f coarse- and fine-grained operations

Tuesday, 20 July 2010