15
A Two-Lock Concurrent Queue Algorithm Maged M. Michael, Michael L. Scott University of Rochester Presented by Hussain Tinwala

A Two-Lock Concurrent Queue Algorithm

Embed Size (px)

DESCRIPTION

A Two-Lock Concurrent Queue Algorithm. Maged M. Michael, Michael L. Scott University of Rochester. Presented by Hussain Tinwala. Two-Lock Algorithm Goals. Provide a higher degree of concurrency Use better blocking techniques Improve performance on shared memory multiprocessor machines. - PowerPoint PPT Presentation

Citation preview

Page 1: A Two-Lock Concurrent Queue Algorithm

A Two-Lock Concurrent Queue Algorithm

Maged M. Michael, Michael L. ScottUniversity of Rochester

Presented by Hussain Tinwala

Page 2: A Two-Lock Concurrent Queue Algorithm

Two-Lock Algorithm Goals

• Provide a higher degree of concurrency

• Use better blocking techniques• Improve performance on shared

memory multiprocessor machines

Page 3: A Two-Lock Concurrent Queue Algorithm

Queue Operations: Enqueue

• EnqueueHead(1)

Tail(4)

Node(2)

Node(3)

1) Create a new nodeNode(5)

2) Insert the node and update the TailHead(1)

Node(4)

Node(2)

Node(3)

Tail(5)

Page 4: A Two-Lock Concurrent Queue Algorithm

Queue Operations: Dequeue

• DequeueHead(1)

Node(4)

Node(2)

Node(3)

Tail(5)

2) Free the first nodeNode(4)

Node(2)

Node(3)

Tail(5)

1) Update the HeadNode(1)

Node(4)

Head(2)

Node(3)

Tail(5)

Page 5: A Two-Lock Concurrent Queue Algorithm

What do single-lock algorithms do?

• They lock the entire queue

• Example: 10 processes want to operate on the queue at the same time {P1, …, P10 }

High Contention

Head(1)

Tail(4)

Node(2)

Node(3)

P1 P2

P3

P4

P5

P6

P7

P8

P9

P10

Page 6: A Two-Lock Concurrent Queue Algorithm

What do two locks do? (1)

• Only lock the Head node or the Tail node

• Enqueue: only needs to read/write the Tail node

• Dequeue: only needs to read/write the Head node

Page 7: A Two-Lock Concurrent Queue Algorithm

What do two locks do? (2)• Example: 10 processes.

Enqueuing processes {E1, …, E5}Dequeuing processes {D1, …, D5}

Head(1)

Tail(4)

Node(2)

Node(3)

D1

D3

D4

D5

E1

E2

E3

E5

D2 E4Increases

ConcurrencyAnd

DecreasesContention

Page 8: A Two-Lock Concurrent Queue Algorithm

Two Critical Mechanisms

There are two kinds of processes:1. Processes that have acquired a lock2. Processes that are trying to acquire a lock

Issues:- Dealing with preemption of processes with

locks (Preemption-safe locking)- Dealing with processes that keep trying to

acquire a lock (Bounded exponential backoff)

Page 9: A Two-Lock Concurrent Queue Algorithm

Preemption-Safe Lockingor Temporary Non-Preemption

(processes holding locks)

Note: There is a bound on how much extra time the process can take after which the scheduler automatically forces preemption.

Page 10: A Two-Lock Concurrent Queue Algorithm

Bounded Exponential Backoff(processes trying to acquire a lock)

• Bounded Exponential Backoff is an algorithm that uses feedback to multiplicatively decrease the rate of some process. Repeated attempts are exponentially delayed (1, 2, 4, 8…) up to a predefined bound.

• The feedback here is that the process fails to acquire the lock

Page 11: A Two-Lock Concurrent Queue Algorithm

Performance of Backoff

From:T. E. Anderson. The Performance of Spin Lock Alternatives for Shared-Memory Multiprocessors. IEEE Transactions on Parallel and Distributed Systems.

Page 12: A Two-Lock Concurrent Queue Algorithm

Single-Lock v. Two-Lock (1)• The two techniques: preemption-safe

locking and bounded exponential backoff can also be used with a single-lock algorithm

• If both algorithms (single-lock and two-lock) use the two techniques, who wins?

• Performance depends on:– Number of processors– Number of programs per processor (level of

multiprogramming)

Page 13: A Two-Lock Concurrent Queue Algorithm

Single Lock v. Two Lock (2)Dedicated Multiprocessor: One process per processor

Crossover points2 processes/processor: 53 processes / processor: 7

Page 14: A Two-Lock Concurrent Queue Algorithm

Verdict

• It depends

• Single-lock better at MP=1, #Processors=2 due to cache misses• Higher degree of multiprogramming means higher chance of

preemption while holding a lock, therefore, two-lock suffers• Two-lock good candidate for dedicated multiprocessor machines

Page 15: A Two-Lock Concurrent Queue Algorithm

End of Slide Show

Questions/Comments?