Beruflich Dokumente
Kultur Dokumente
1
© 2013 A. Haeberlen, Z. Ives University of Gujrat
Where are we?
Basics: Scalability, concurrency, consistency...
Cloud basics: EC2, EBS, S3, SimpleDB, ...
Cloud programming: MapReduce, Hadoop, ...
Algorithms: PageRank, adsorption, ...
Web programming, servlets, XML, Ajax...
Beyond MapReduce: Dryad, Hive, PigLatin, ...
2
© 2013 A. Haeberlen, Z. Ives University of Gujrat
Scale increases complexity
Wide-area
network
More challenges
3
© 2013 A. Haeberlen, Z. Ives University of Gujrat
Fear not!
You will hear about many tricky challenges
Packet loss, faulty machine, network partition, inconsistency,
variable memory latencies, deadlocks...
4
© 2013 A. Haeberlen, Z. Ives University of Gujrat
Symmetric Multiprocessing (SMP)
Memory bus
6
© 2013 A. Haeberlen, Z. Ives University of Gujrat
What is scalability?
A system is scalable if it can easily adapt to
increased (or reduced) demand
Example: A storage system might start with a capacity of
just 10TB but can grow to many PB by adding more nodes
Scalability is usually limited by some sort of bottleneck
7
© 2013 A. Haeberlen, Z. Ives University of Gujrat
Parallelization
void bubblesort(int nums[]) {
boolean done = false;
while (!done) { int[] mergesort(int nums[]) {
done = true; int numPieces = 10;
for (int i=1; i<nums.length; i++) { int pieces[][] = split(nums, numPieces);
if (nums[i-1] > nums[i]) { for (int i=0; i<numPieces; i++)
swap(nums[i-1], nums[i]); sort(pieces[i]);
done = false; return merge(pieces);
} }
}
}
} Can be done in parallel!
Cores used
9
© 2013 A. Haeberlen, Z. Ives University of Gujrat
....
Amdahl's law
Parallel Core #6
part Sequential
Core #5
parts
Core #4
Core #3 Core #3
Core #2 Core #2
Core #1 Core #1
Cores
START Dependencies
...
Individual
tasks DONE DONE
14
© 2013 A. Haeberlen, Z. Ives University of Gujrat
Recap: Parallelization
Parallelization is hard
Not all algorithms are equally parallelizable -- need to pick
very carefully
15
© 2013 A. Haeberlen, Z. Ives University of Gujrat
Plan for the next two lectures
Parallel programming and its challenges
Parallelization and scalability, Amdahl's law
Synchronization, consistency NEXT
16
© 2013 A. Haeberlen, Z. Ives University of Gujrat
Why do we need synchronization?
17
© 2013 A. Haeberlen, Z. Ives University of Gujrat
Why do we need synchronization?
$100
1) B=Balance(Bob) 1) A=Balance(Alice)
2) A=Balance(Alice) 2) B=Balance(Bob)
3) SetBalance(Bob,B+100) 3) SetBalance(Alice,A+500)
4) SetBalance(Alice,A-100) 4) SetBalance(Bob,B-500)
Time
1 2 3 4
Alice's balance: $200 $200 $700 $700 $100
Bob's balance: $800 $900 $900 $300 $300
18
© 2013 A. Haeberlen, Z. Ives University of Gujrat
Problem: Race condition
void transferMoney(customer A, customer B, int amount)
{
showMessage("Transferring "+amount+" to "+B);
Alice's and Bob's
int balanceA = getBalance(A);
threads of execution int balanceB = getBalance(B);
setBalance(B, balanceB + amount);
setBalance(A, balanceA - amount);
showMessage("Your new balance: "+(balanceA-amount));
}
What happened?
Race condition: Result of the computation depends on the
exact timing of the two threads of execution, i.e., the order
in which the instructions are executed
Reason: Concurrent updates to the same state
Can you get a race condition when all the threads are reading the data,
and none of them are updating it?
19
© 2013 A. Haeberlen, Z. Ives University of Gujrat
Goal: Consistency
What should have happened?
Intuition: It shouldn't make a difference whether the
requests are executed concurrently or not
20
© 2013 A. Haeberlen, Z. Ives University of Gujrat
Sequential consistency
Core #1: T2 T4 T5 Actual
execution
Core #2: T1 T3 T6
Time
Hypothetical
Single core: T1 T2 T5 execution
T3 T6 T4
Time
Same start Same
state result
Sequential consistency:
The result of any execution is the same as if the operations
of all the cores had been executed in some sequential order,
and the operations of each individual processor appear in
this sequence in the order specified by the program
21
© 2013 A. Haeberlen, Z. Ives University of Gujrat
Other consistency models
Strong consistency
After update completes, all subsequent accesses will return
the updated value
Weak consistency
After update completes, accesses do not necessarily return
the updated value; some condition must be safisfied first
Example: Update needs to reach all the replicas of the object
Eventual consistency
Specific form of weak consistency: If no more updates are
made to an object, then eventually all reads will return the
latest value
Variants: Causal consistency, read-your-writes, ...
More of this later in the course!
23
© 2013 A. Haeberlen, Z. Ives University of Gujrat
Mutual exclusion
void transferMoney(customer A, customer B, int amount)
{
showMessage("Transferring "+amount+" to "+B);
int balanceA = getBalance(A);
Critical section int balanceB = getBalance(B);
setBalance(B, balanceB + amount);
setBalance(A, balanceA - amount);
showMessage("Your new balance: "+(balanceA-amount));
}
1 2 3 4 5 6 7 8
blocked Time
1 12 2 3 4 5 6 7 8
Alice's balance: $200 $200 $100 $600 $600
Bob's balance: $800 $900 $900 $900 $400
26
© 2013 A. Haeberlen, Z. Ives University of Gujrat
Problem: Deadlock
$100
1 2
blocked (waiting for lock on Alice)
Philosopher:
repeat
think
pick up left fork
pick up right fork
eat
put down forks
forever
28
© 2013 A. Haeberlen, Z. Ives University of Gujrat
What to do about deadlocks
Many possible solutions, including:
Lock manager: Hire a waiter and require that philosophers
must ask the waiter before picking up any forks
Consequences for scalability?
Chandy/Misra solution:
Forks can either be dirty or clean; initially all forks are dirty
After the philosopher has eaten, all his forks are dirty
When a philosopher needs a fork he can't get, he asks his neighbor
If a philosopher is asked for a dirty fork, he cleans it and gives it up
If a philosopher is asked for a clean fork, he keeps it
29
© 2013 A. Haeberlen, Z. Ives University of Gujrat
Plan for the next two lectures
Parallel programming and its challenges
Parallelization and scalability, Amdahl's law
Synchronization, consistency
Mutual exclusion, locking, issues related to locking
Architectures: SMP, NUMA, Shared-nothing NEXT
30
© 2013 A. Haeberlen, Z. Ives University of Gujrat
Other architectures
Earlier assumptions:
All cores can access the same memory
?
Memory bus
32
© 2013 A. Haeberlen, Z. Ives University of Gujrat
Non-Uniform Memory Architecture (NUMA)
34
© 2013 A. Haeberlen, Z. Ives University of Gujrat
Shared-Nothing
Network
35
© 2013 A. Haeberlen, Z. Ives University of Gujrat
Plan for the next two lectures
Parallel programming and its challenges
Parallelization and scalability, Amdahl's law
Synchronization, consistency
Mutual exclusion, locking, issues related to locking
Architectures: SMP, NUMA, Shared-nothing
All about the Internet in 30 minutes NEXT
36
© 2013 A. Haeberlen, Z. Ives University of Gujrat
http://www.flickr.com/photos/brandoncripps/623631374/sizes/l/in/photostream/
Stay tuned
37
© 2013 A. Haeberlen, Z. Ives University of Gujrat