Concurrency and Parallelism
Concurrency and Parallelism
and Parallelism
Suresh Jagannathan
[email protected]
http://www.cs.purdue.edu/homes/suresh
and
Ananth Grama
[email protected]
http://www.cs.purdue.edu/homes/ayg
http://www.cs.purdue.edu/homes/suresh/CS390C
Non-concurrent
serial server
request 2 request 1
t=0
request 2 request 1
t=0
request 2 request 1
t=6
request 2 request 1
t=8
Total completion time = 8 units, Average service time = (6 + 8)/2 = 7 units
CS390C: Principles of Concurrency and Parallelism
Try a concurrent server now!
request 1
request 2
t=0
request 1
request 2
t=1
request 1
request 2
t=2
t=3
t=4
t=8
Total completion time = 8 units, Average service time = (4 + 8)/2 = 6 units
CS390C: Principles of Concurrency and Parallelism
Why Concurrency?
● The lesson from the example is quite simple:
− Not knowing anything about execution times, we
can reduce average service time for requests by
processing them concurrently!
● But what if I knew the service time for each
request?
− Would “shortest job first” not minimize average
service time anyway?
− Aha! But what about the poor guy standing at the
back never getting any service (starvation/
fairness)?
CS390C: Principles of Concurrency and Parallelism
Why Concurrency?
● Notions of service time, starvation, and fairness
motivate the use of concurrency in virtually all
aspects of computing:
− Operating systems are multitasking
− Web/database services handle multiple concurrent
requests
− Browsers are concurrent
− Virtually all user interfaces are concurrent