11
Chapter 11 Resource Allocation by Mikhail Nesterenko “Distributed Algorithms” by Nancy A. Lynch

Chapter 11 Resource Allocation by Mikhail Nesterenko “Distributed Algorithms” by Nancy A. Lynch

Embed Size (px)

Citation preview

Page 1: Chapter 11 Resource Allocation by Mikhail Nesterenko “Distributed Algorithms” by Nancy A. Lynch

Chapter 11Resource Allocation

by Mikhail Nesterenko

“Distributed Algorithms”

by Nancy A. Lynch

Page 2: Chapter 11 Resource Allocation by Mikhail Nesterenko “Distributed Algorithms” by Nancy A. Lynch

Outline• specification for resource allocation problems

– explicit resource specification, exclusion specification• general resource allocation problem

– its properties• dining philosophers problem

– lack of symmetric solution– RightLeft solution

• generalization to resource allocation problem– coloring– using hierarchical coloring to solve the problem

• randomized symmetric solution to dining philosophers

Page 3: Chapter 11 Resource Allocation by Mikhail Nesterenko “Distributed Algorithms” by Nancy A. Lynch

Explicit Resource and Exclusion Specifications

Two ways of describing conflict relationships among users• explicit resource specification

– a finite set of resources – a subset of resources for each process (to perform its work)

two users conflict if their resource sets intersect (see Example 11.1.1)

• exclusion specification – exclusion set E – a collection of sets of processes which cannot

perform their work simultaneously, exclusion set is closed under superset (if a set S contains a subset in E then S is also in E)

Example 11.1.2 – exclusion set contains any subset of processes with cardinality greater than 1, Example 11.1.3 – k-exclusion

explicit resource spec gives rise to exclusion spec (see.Example 11.1.5)

reverse is not true, example?

Page 4: Chapter 11 Resource Allocation by Mikhail Nesterenko “Distributed Algorithms” by Nancy A. Lynch

Resource Allocation Problem

user cycles through R(emainder), T(rying), C(rticial) and E(xit) regions

Properties are similar to MX problem (ch.10)• well-formedness – interactions between the users and algorithms

are well-formed (no CS access without request, etc.)• exclusion – no reachable system state where the set of users is in

the exclusion set• progress (for T) – if a process is in T then some user enters C

(same for E)• independent progress (for T) – if process is in T and all conflicting

users are in R then eventually the process enters C or some conflicting user enters T (same for E)

Note: independent progress is rather weak, any stronger properties?

Page 5: Chapter 11 Resource Allocation by Mikhail Nesterenko “Distributed Algorithms” by Nancy A. Lynch

Stronger Liveness Properties of RAP

lockout freedom (for T) – if all users always return the resource, then any user that reaches T eventually enters C (same for E)

time bound (for T) – – if each user always returns the resource within constant time and time between successive steps of each process is bounded then each user enters C in finite time

bounded bypass (from MX, how is it different for RAP?) – while one process remains in T another process can only enter C at most some bounded number of times

Lemma 11.1• if resource allocation algorithm has any time bound, then it is lockout-

free• if an algorithm guarantees well-formedness and lockout-freedome

then it also guarantees progress

Page 6: Chapter 11 Resource Allocation by Mikhail Nesterenko “Distributed Algorithms” by Nancy A. Lynch

Dining Philosophers Problem (DP)• special case of RAP• processes (philosophers) are connected in a ring, each pair of

neighboring processes has exactly one resource conflict (fork), see Fig 11.1

• we only consider solutions with one read-modify-write shared variable associated with each resource

• symmetric algorithms – processes are identical, shared variables have the same initial values (a process cannot distinguish itself from others)

• Theorem 11.2 there is no symmetric solution to DP– idea – there is no way to break the symmetry between processes

so there is no way for one neighbor to enter C while another waits

• what’s wrong with the following solution?– each process picks up its right fork (if its available, if not – waits)

and then picks up its left fork (if its available, if not – waits)

Page 7: Chapter 11 Resource Allocation by Mikhail Nesterenko “Distributed Algorithms” by Nancy A. Lynch

Right-Left DP Solution• waiting chain – a set sequence of processes where each consequent

process waits on the resource held by the preceding process (see Fig 11.3)– processes in the waiting chain must enter the CS sequentially (is

this so?)• RightLeftDP solution: odd processes go for the right fork first, even –

for the left

Theorem 11.4 (simplified) – RightLeftDP solves DP and guarantees, lockout-freedom, independent progress, and a constant time bound

Page 8: Chapter 11 Resource Allocation by Mikhail Nesterenko “Distributed Algorithms” by Nancy A. Lynch

Generalization to RAP: Resource Graph• assume resources are totally ordered (hierarchical resource

allocation)• idea – if process I waits for a resource held by process J, then J

could only be delayed by waiting for a resource that is strictly larger (in resource ordering) than what I is waiting for

• resource graph– each node is a resource– two nodes are connected by an edge if there is a process that

needs both resources• color the resource graph, order colors (see figs 11.4, 11.5)

– this way the resources for each process are totally ordered

Page 9: Chapter 11 Resource Allocation by Mikhail Nesterenko “Distributed Algorithms” by Nancy A. Lynch

Generalization to RAP: Algorithm• each process obtains resources in the increasing order of the colors

– each resource has a queue associated with it– process requests resource by placing its index at the end of the

queue,• process removes its index in E• process gets the resource when its index is at the top of the

queue• a process I may be waiting on another process J only if J is obtaining

a higher color– hence, the largest length of the waiting chain is the number of

colors in the graph• Theorem 11.5 (simplified) If the max number of colors and max

number of users of a single resource is constant the coloring algorithm has a constant time bound

Page 10: Chapter 11 Resource Allocation by Mikhail Nesterenko “Distributed Algorithms” by Nancy A. Lynch

Randomized DP Algorithm

idea – a trying process executes a loop, in each iteration the process• randomly selects a fork• waits until it is available (why can’t we just drop it and randomly

select a different fork?)• checks to see if the other is available

– if yes – go to C– if no – drop both forks

the algorithm– solves DP even if the processes are identical– guarantees exclusion (with certainty)– ensures progress with probability 1

Page 11: Chapter 11 Resource Allocation by Mikhail Nesterenko “Distributed Algorithms” by Nancy A. Lynch

Properties of the Randomized Algorithm• deterministically guarantees well-formedness, exclusion, and

individual progress • Example 11.4.1: the randomized algorithm does not deterministically

guarantee progress– consider the case where all processes make the same random

choices• Theorem 11.17 The randomized algorithm guarantees progress with

probability 1