Replication and Consistency 06 The Relative Power of Synchronization - - PowerPoint PPT Presentation

replication and consistency
SMART_READER_LITE
LIVE PREVIEW

Replication and Consistency 06 The Relative Power of Synchronization - - PowerPoint PPT Presentation

Replication and Consistency 06 The Relative Power of Synchronization Operations Annette Bieniusa AG Softech FB Informatik TU Kaiserslautern Annette Bieniusa Replication and Consistency 1/ 45 Thank you! These slides are based on companion


slide-1
SLIDE 1

Replication and Consistency

06 The Relative Power of Synchronization Operations Annette Bieniusa

AG Softech FB Informatik TU Kaiserslautern

Annette Bieniusa Replication and Consistency 1/ 45

slide-2
SLIDE 2

Thank you!

These slides are based on companion material of the following books: The Art of Multiprocessor Programming by Maurice Herlihy and Nir Shavit Synchronization Algorithms and Concurrent Programming by Gadi Taubenfeld

Annette Bieniusa Replication and Consistency 2/ 45

slide-3
SLIDE 3

Motivation

Annette Bieniusa Replication and Consistency 3/ 45

slide-4
SLIDE 4

Last lecture: Foundations of Shared Memory

To understand modern multiprocessors we need to ask some basic questions: What is the weakest useful form of shared memory? What concurrent problem is (and what isn’t) computable under a given memory model?1

1Efficiency is mostly irrelevant here. Annette Bieniusa Replication and Consistency 4/ 45

slide-5
SLIDE 5

Last lecture: From the Weakest Register to Atomic Snapshot!

Annette Bieniusa Replication and Consistency 5/ 45

slide-6
SLIDE 6

Last lecture: From the Weakest Register to Atomic Snapshot!

But some synchronization problems require more powerful registers!

Annette Bieniusa Replication and Consistency 5/ 45

slide-7
SLIDE 7

Wait-Free Implementations

Strongest non-blocking progress guarantee For every operation / method call, there is a bound on the number of steps that the algorithm will take before the operation completes

Annette Bieniusa Replication and Consistency 6/ 45

slide-8
SLIDE 8

Wait-Free Implementations

Strongest non-blocking progress guarantee For every operation / method call, there is a bound on the number of steps that the algorithm will take before the operation completes It implies that the algorithm does not rely on mutual exclusion!

Annette Bieniusa Replication and Consistency 6/ 45

slide-9
SLIDE 9

The Consensus Problem

Annette Bieniusa Replication and Consistency 7/ 45

slide-10
SLIDE 10

The Consensus Problem

Each process pi proposes a value vi All processes have to agree on some common value v that is the initial value of some pi

Annette Bieniusa Replication and Consistency 8/ 45

slide-11
SLIDE 11

The Consensus Problem

Each process pi proposes a value vi All processes have to agree on some common value v that is the initial value of some pi Properties of Consensus: Uniform Agreement: Every process must decide on the same value. Integrity: Every process decides at most one value, and if it decides some value, then it must have been proposed by some process. Termination: All processes eventually reach a decision. Validity: If all processes propose the same value v, then all processes decide v.

Annette Bieniusa Replication and Consistency 8/ 45

slide-12
SLIDE 12

Implementing Consensus based on FIFO Queues

Assume we have a linearizable FIFO-Queue for two dequeuers. How can we use it to implement consensus for two threads?

Annette Bieniusa Replication and Consistency 9/ 45

slide-13
SLIDE 13

Theorem

Asynchronous computability is fundamentally different from Turing computability! Adapted version of fundamental theorem by Fisher, Lynch, Peterson for distributed computing (Fischer, Lynch, and Paterson 1985) which received the Dijkstra prize for the most influential paper in distributed computing in 2001 There is no wait-free (deterministic) implementation of n-thread consensus (n > 1) from read-write registers.

Annette Bieniusa Replication and Consistency 10/ 45

slide-14
SLIDE 14

Proof Strategy

Assume that there is a wait-free (deterministic) implementation . . . Reason about the properties of any such protocol Derive a contradiction ⇒ Done :)

Annette Bieniusa Replication and Consistency 11/ 45

slide-15
SLIDE 15

Proof Strategy

Assume that there is a wait-free (deterministic) implementation . . . Reason about the properties of any such protocol Derive a contradiction ⇒ Done :) Suffices to consider n = 2 processes and binary consensus (i.e. proposed values are either 0 or 1)

Annette Bieniusa Replication and Consistency 11/ 45

slide-16
SLIDE 16

Essence of wait-free computation

Either A or B moves “Moving” here means

reads a register, or writes a register

For two processes, wait-free computations can be modeled as tree

Annette Bieniusa Replication and Consistency 12/ 45

slide-17
SLIDE 17

Decision Values

Annette Bieniusa Replication and Consistency 13/ 45

slide-18
SLIDE 18

Univalent States: Single Value Possible

Annette Bieniusa Replication and Consistency 14/ 45

slide-19
SLIDE 19

Bivalent Statues: Both Values Possible

Annette Bieniusa Replication and Consistency 15/ 45

slide-20
SLIDE 20

Proof Part 1: Some initial state is bivalent

If both processors input 0: All executions must decide on 0 Including the solo execution by process A

Annette Bieniusa Replication and Consistency 16/ 45

slide-21
SLIDE 21

Proof Part 1: Some initial state is bivalent

If both processors input 0: All executions must decide on 0 Including the solo execution by process A If both processors input 1: All executions must decide on 1 Including the solo execution by process B

Annette Bieniusa Replication and Consistency 16/ 45

slide-22
SLIDE 22

Proof Part 1: Some initial state is bivalent

If the inputs differ: Solo execution of A decides 0 Solo execution of B decides 1 Bivalent state!

Annette Bieniusa Replication and Consistency 17/ 45

slide-23
SLIDE 23

Critical State

Annette Bieniusa Replication and Consistency 18/ 45

slide-24
SLIDE 24

Proof Part 2: Some state must be a critical state

Starting from a bivalent initial state, the protocol will reach a critical state

Otherwise we could stay bivalent forever

Annette Bieniusa Replication and Consistency 19/ 45

slide-25
SLIDE 25

Proof Part 3: Properties of read-write registers

Lets look at executions that: Start from a critical state In which processes cause state to become univalent by next step, that is reading or writing to same/different registers End within a finite number of steps deciding either 0 or 1 Show that there are no critical states! ⇒ Contradiction

Annette Bieniusa Replication and Consistency 20/ 45

slide-26
SLIDE 26

Possible Interactions

Annette Bieniusa Replication and Consistency 21/ 45

slide-27
SLIDE 27

Case 1: Some Thread Reads

Annette Bieniusa Replication and Consistency 22/ 45

slide-28
SLIDE 28

Case 2: Threads write distinct registers

Annette Bieniusa Replication and Consistency 23/ 45

slide-29
SLIDE 29

Case 3: Threads write same register

Annette Bieniusa Replication and Consistency 24/ 45

slide-30
SLIDE 30

Implications

Corollary

It is impossible to implement a two-dequeuer wait-free FIFO queue from read/write registers.

Annette Bieniusa Replication and Consistency 25/ 45

slide-31
SLIDE 31

Measuring Synchronization Power

An object X has consensus number n if it can be used to solve n-thread consensus. Take any number of instances of X together with atomic read/write registers and implement n-thread consensus But not (n+1)-thread consensus If you can implement X from Y and X has consensus number c, then Y has consensus number at least c.

Annette Bieniusa Replication and Consistency 26/ 45

slide-32
SLIDE 32

Consensus Protocol for N threads and integer values

// For N threads: abstract class ConsensusProtocol { protected int[] proposed = new int[N]; private void propose(int value) { proposed[ThreadID.get()] = value; } abstract int decide(int value); }

Annette Bieniusa Replication and Consistency 27/ 45

slide-33
SLIDE 33

Read-Modify-Write Registers

public abstract class RMWRegister { private int value; // here: synchronized indicates atomic execution of all instructions in the method; actually implemented using a hardware primitive public synchronized int getAndMumble() { // return prior value int prior = this.value; // apply function to current value and replace this.value = mumble(this.value); return prior; } }

Annette Bieniusa Replication and Consistency 28/ 45

slide-34
SLIDE 34

Example: getAndSet

abstract class RMWRegister { private int value; public synchronized int getAndSet(int v) { int prior = this.value; this.value = v; return prior; } ... }

Annette Bieniusa Replication and Consistency 29/ 45

slide-35
SLIDE 35

Example: getAndIncrement

abstract class RMWRegister { private int value; public synchronized int getAndIncrement() { int prior = this.value; this.value = this.value + 1; return prior; } ... }

Annette Bieniusa Replication and Consistency 30/ 45

slide-36
SLIDE 36

Example: getAndAdd

abstract class RMWRegister { private int value; public synchronized int getAndAdd(int a) { int prior = this.value; this.value = this.value + a; return prior; } ... }

Annette Bieniusa Replication and Consistency 31/ 45

slide-37
SLIDE 37

Example: get

abstract class RMWRegister { private int value; public synchronized int get() { int prior = this.value; // this.value = this.value; return prior; } ... }

Annette Bieniusa Replication and Consistency 32/ 45

slide-38
SLIDE 38

Example: compareAndSet

abstract class RMWRegister { private int value; public synchronized boolean compareAndSet(int expected, int update) { int prior = this.value; if (this.value == expected) { this.value = update; return true; } return false; } ... }

Annette Bieniusa Replication and Consistency 33/ 45

slide-39
SLIDE 39

Definition

An RMW method with function mumble(x) is non-trivial if there exists a value v such that v != mumble(v).

Annette Bieniusa Replication and Consistency 34/ 45

slide-40
SLIDE 40

Definition

An RMW method with function mumble(x) is non-trivial if there exists a value v such that v != mumble(v). Example:

getAndIncrement is

Annette Bieniusa Replication and Consistency 34/ 45

slide-41
SLIDE 41

Definition

An RMW method with function mumble(x) is non-trivial if there exists a value v such that v != mumble(v). Example:

getAndIncrement is non-trivial get is

Annette Bieniusa Replication and Consistency 34/ 45

slide-42
SLIDE 42

Definition

An RMW method with function mumble(x) is non-trivial if there exists a value v such that v != mumble(v). Example:

getAndIncrement is non-trivial get is trivial

Theorem

Any non-trivial RMW object has consensus number at least 2.

Annette Bieniusa Replication and Consistency 34/ 45

slide-43
SLIDE 43

Proof Sketch: Implementing 2-thread consensus with RMW

class RMWConsensus extends ConsensusProtocol { // x is arbitrary fixed value with mumble(x) != x private RMWRegister r = new RMWRegister(x); public int decide(int value) { propose(value); // first thread reaching the getAndMumble reads x if (r.getAndMumble() == x) return proposed[ThreadID.get()]; else return proposed[1 - ThreadID.get()]; } }

Annette Bieniusa Replication and Consistency 35/ 45

slide-44
SLIDE 44

Proof Sketch: Implementing 2-thread consensus with RMW

class RMWConsensus extends ConsensusProtocol { // x is arbitrary fixed value with mumble(x) != x private RMWRegister r = new RMWRegister(x); public int decide(int value) { propose(value); // first thread reaching the getAndMumble reads x if (r.getAndMumble() == x) return proposed[ThreadID.get()]; else return proposed[1 - ThreadID.get()]; } }

Question

Why doesn’t this construction work for more than 2 threads?

Annette Bieniusa Replication and Consistency 35/ 45

slide-45
SLIDE 45

Interfering RMW

Let F be a set of functions such that for all fi, fj ∈ F either commute: fi(fj(v)) = fj(fi(v))

  • verwrite: fi(fj(v)) = fi(v)

Theorem

Any set of RMW objects with mumble function that commutes or

  • verwrites has consensus number exactly 2.

Annette Bieniusa Replication and Consistency 36/ 45

slide-46
SLIDE 46

Proof sketch: Commuting functions

Annette Bieniusa Replication and Consistency 37/ 45

slide-47
SLIDE 47

Proof sketch: Overwriting functions

Annette Bieniusa Replication and Consistency 38/ 45

slide-48
SLIDE 48

Your turn!

Using the results so far, derive the consensus numbers for the following objects! Justify your answer!

1 Register with getAndIncrement operation 2 Register with getAndSet operation 3 Register with compareAndSwap operation

Annette Bieniusa Replication and Consistency 39/ 45

slide-49
SLIDE 49

compareAndSet has Consensus Number ∞

Construct consensus protocol for any number of threads Assumption here is that the AtomicInteger is not restricted as in Java, but can represent any integral number

class RMWConsensus extends ConsensusProtocol { private AtomicInteger r = new AtomicInteger(-1); int decide(int value) { propose(value); // first thread executing compareAndSet puts its thread id r r.compareAndSet(-1, ThreadID.get()); return proposed[r.get()]; } }

Annette Bieniusa Replication and Consistency 40/ 45

slide-50
SLIDE 50

Fun Fact: Every consensus number has an object!

Atomic k-assignment solves consensus for 2k-2 threads Can be extended to odd numbers

Annette Bieniusa Replication and Consistency 41/ 45

slide-51
SLIDE 51

Impact of these Results

Many early machines provided these “weak” RMW instructions (i.e. with consensus number ≤ 2)

Test-and-set (IBM 360) Fetch-and-add (NYU Ultracomputer) Swap (Original SPARCs)

We now understand their limitations But why do we want consensus anyway?

Annette Bieniusa Replication and Consistency 42/ 45

slide-52
SLIDE 52

Theorem: Consensus is Universal!(Herlihy 1991)

From n-process consensus, we can construct a wait-free/lock-free linearizable n-threaded implementation

  • f any sequentially specified object!

⇒ Next lecture!

Annette Bieniusa Replication and Consistency 43/ 45

slide-53
SLIDE 53

Summary

Consensus problem as classical concurrent problem Fundamental impossibility result by Fischer-Lynch-Paterson (adapted by Maurice Herlihy) Hierarchy of synchronization operations based on consensus numbers

Annette Bieniusa Replication and Consistency 44/ 45

slide-54
SLIDE 54

Further reading

Fischer, Michael J., Nancy A. Lynch, and Mike Paterson. 1985. “Impossibility of Distributed Consensus with One Faulty Process.” J. ACM 32 (2): 374–82. https://doi.org/10.1145/3149.214121. Herlihy, Maurice. 1991. “Wait-Free Synchronization.” ACM Trans.

  • Program. Lang. Syst. 13 (1): 124–49.

https://doi.org/10.1145/114005.102808.

Annette Bieniusa Replication and Consistency 45/ 45