Download Load Balancing or Task Scheduling - Lecture Slides | CS 415 and more Study notes Computer Science in PDF only on Docsity!
Load Balancing
Jingke Li
Portland State University
Jingke Li (Portland State University) CS 415/515 Load Balancing 1 / 23
Task Scheduling/Load Balancing
Assign computation tasks to processors in a way to minimize the total execution time and/or to maximize processor utilization.
Approaches:
- Static — Task Scheduling:
- Optimal
- Sub-Optimal (approximate or heuristic)
- (^) Dynamic — Load Balancing:
- Centralized
- Distributed (sender-initiated or receiver-initiated)
Static Task Scheduling
Given a set of n processors, a set of l tasks with a precedence relation (represented by a DAG), and a cost function for tasks. Also given an integer k. Does there exists a mapping function from tasks to processors such that the resulting parallel computation’s execution time < k?
Known Results:
Task Task Number Comm. Complexity Graph Costs of Procs Cost Tree arbitrary any ignored O(n) DAG uniform 2 ignored O(n^2 ) DAG uniform 2 considered ?? DAG uniform any ignored NP-complete DAG uniform any considered NP-complete DAG 1 or 2 units ≥ 2 ignored NP-complete DAG arbitrary any ignored NP-complete
Jingke Li (Portland State University) CS 415/515 Load Balancing 3 / 23
Hu’s Level-Based List Scheduling Algorithm[’61]
An optimal algorithm for scheduling tree-structured uniform task graphs.
- The level of each node in the tree is calculated and used as its priority.
- Whenever a processor becomes available, assign it the ready task with the highest priority.
Example:
T 1 T 2 T 3 T 4
T 5 T 6 T 7
T 8 T 9
T 10
P1 T 1 T 3 T 5 T 7 T 9
P2 T 2 T 4 T 6 T 8 T 10
P1 T 1 T 5 T 9 T 10
P2 T 2 T 6
P3 T 3 T 7
P4 T 4 T 8
Example
T 1 T 2 T 3
T 4 T 5 T 6 T 7
T 8 T 9
T 10
T 11
A possible list is
T 1 , T 2 , T 3 , T 4 , T 5 , T 6 , T 7 , T 8 , T 9 , T 10 , T 11 P1 T 1 T 3 T 5 T 7 T 9 T 10 T 11 P2 T 2 T 4 T 6 T 8
Jingke Li (Portland State University) CS 415/515 Load Balancing 7 / 23
Graham’s Algorithm (cont.)
Issues:
Un-expected behaviors may occur:
- When the number of processors is increased,
- Or, the execution times of some tasks are decreased,
- Or, some of the precedence constraints are eliminated
The length of the schedule generated using this algorithm can actually increase!
Coffman-Graham Algorithm[’72]
An optimal algorithm for scheduling DAGs of uniform tasks to two processors. (Based on Graham’s algorithm, but constructs the list in a special way.)
T = {T 1 , T 2 ,... , Tn} — a set of unit-time tasks with a partial order defined on them. S(T ) — the set of immediate successors of T. α(T ) — an integer label assigned to T. N(T ) — the decreasing integer sequence formed by ordering the set {α(T ′) | T ′^ ∈ S(T )}.
Jingke Li (Portland State University) CS 415/515 Load Balancing 9 / 23
Coffman-Graham Algorithm (cont.)
- Choose an arbitrary task Tk from T such that S(Tk ) = φ, and defined α(Tk ) to be 1.
- for i ← 2 to n do 2.1 R be the set of unlabeled tasks with no unlabeled successors 2.2 Let T ′^ be the task in R such that N(T ′) is lexical-graphically smallest 2.3 Let α(T ′) ← i
- Construct a list of tasks L = (Un, Un− 1 ,... , U 2 , U 1 ) such that α(Ui ) = i for all i where 1 ≤ i ≤ n.
- Given (T , ≺, L), use Graham’s algorithm to schedule the tasks in T.
Theorem.
SCG
SOpt
p
. (It produces near-optimal result when p > 2.)
Another Example
T 1 T 2 T 3
T 4 T 5 T 6 T 7
T 8 T 9
T 10
T 11 1
2
3 4
5 6 7 8
9 10 11 Resulting list: T 3 , T 2 , T 1 , T 7 , T 6 , T 6 , T 4 , T 9 , T 8 , T 10 , T 11 For p = 2: P1 T 3 T 1 T 6 T 4 T 8 T 11 P2 T 2 T 7 T 5 T 9 T 10
This is an optimal schedule!
Jingke Li (Portland State University) CS 415/515 Load Balancing 13 / 23
Dynamic Load Balancing
Flaws with Static Scheduling: (Even if a mathematical solution exists.)
- Very difficult to estimate accurately the execution times of various parts of a program without actually executing the parts.
- Communication delays that vary under different circumstances.
- (^) Some problems have an indeterminate number of steps to reach their solution.
With dynamic load balancing, all these factors are taken into account by making the division of load dependent upon the execution of the parts as they are being executed. However, dynamic load balancing does incur an overhead during execution.
Dynamic Load Balancing Strategies
- Centralized Queue — Tasks are handed out from a centralized location. A clear master-slave structure exists. - The master process holds the collection of tasks to be performed. Tasks are sent to the slave processes. - When a slave process completes one task, it requests another task from the master process.
Jingke Li (Portland State University) CS 415/515 Load Balancing 15 / 23
Strategies (cont.)
- (^) Distributed Queue — Tasks are generated from a master processor, and are forwarded to worker processors. - Each worker processor has a buffer for holding task(s). - Each worker processor has two processes running, one for processing tasks, the other for handling communication.
Distributed Termination Detection
The conditions for distributed termination at time t are:
- local termination conditions are met throughout the collection of processes, at time t (could be application-specific);
- there are no messages in transit between processes at time t. (This condition is necessary because a message in transit might restart a terminated process.)
The second condition is more difficult to recognize. The time that it takes for messages to transit will not be known in advance.
Jingke Li (Portland State University) CS 415/515 Load Balancing 19 / 23
Using Acknowledgment Messages
Each process is in one of two states: idle or active. Initially, it is in the idle state. Upon receiving a task, it changes to the active state.
- The process that sends a task to an idle process becomes its “parent.” Each active process has a unique parent.
- When a process receives a task, it immediately sends an acknowledgment message, except if the process it receives the task from is its parent. It only sends an ack message to its parent when it is ready to become idle.
- A process becomes idle when
- Its local termination condition exists (all tasks are completed), and
- it has transmitted all its acks for tasks it has received, and
- itt has received all its acks for tasks it has sent out.
- When the first process becomes idle, the computation can terminate.
Single-Pass Ring Termination Algorithm
If a process cannot be reactivated after reaching its local termination condition, then we can use this simple token-passing algorithm.
- When process P 0 has terminated, it generates a token that is passed to process P 1.
- When process Pi (1 ≤ i < n) receives the token and has already terminated, it passes the token onward to process Pi +1. Otherwise, it waits for its local termination condition and then passes the token onward. Process Pn− 1 passes the token to process P 0.
- When process P 0 receives a token, it knows that all processes in the ring have terminated. A message can then be sent to all processes informing them of global termination, if necessary.
This algorithm does not apply to cases in which a process can pass a new task to an idle process.
Jingke Li (Portland State University) CS 415/515 Load Balancing 21 / 23
Dual-Pass Ring Termination Algorithm
In this algorithm, tokens are colored white or black. Processes are also colored white or black. Receiving a black token means that global termination may not have occurred and the token must be recirculated around the ring again.
Process Coloring:
- If Pi passes a task backwards to Pj where j < i, it becomes a black process; otherwise it is a white process.
- A black process will color a token black and pass it on. A white process will pass on the token in its original color (either black or white).
- After Pi has passed on a token, it becomes a white process.