Previous | Next --- Slide 4 of 46
Back to Lecture Thumbnails
kayvonf

Question: In 15-213's web proxy assignment you gained experience writing concurrent programs using pthreads. Think about your motivation for programming with threads in that assignment. How was it different from the motivation to create multi-threaded programs in this class?

Hint: What is the difference between concurrent execution and parallel execution?

anonymous

In the 15213's web proxy assignment, we use pthreads to realize concurrent execution to speed up the program. That's built on a single-core computer and the scheduler help us to manage the execution. However, in this class, we can use parallel execution (one processor/thread on each core) to speed up the program because of the hardware support. This is impossible for the web proxy assignment.

jocelynh

A clarification on concurrent vs. parallel: Parallel execution refers to tasks being executed at the same time, while concurrent execution of threads may not necessarily happen in parallel. (Tasks in concurrent threads can be interleaved, the threads could be executed one after another, or they could occur in parallel, as the OS schedules execution.)

bharadwaj

(Please correct me if this is wrong)

Concurrency does not necessarily need parallelism. You can run a program with multiple threads on a single-core computer, or a multi-core computer. It doesn't matter. Concurrent programming does introduce the possibility of non-deterministic interleaving, and we have nice synchronization tools like mutexes to control this interleaving.

On the other hand, a parallel program runs on multiple processors.

paracon

I remember listening to Rob Pike's talk about Go Lang in a conference, and I found the definition really useful : Concurrency is about dealing with a lot of things at once, and Parallelism is about doing lots of things at once. Like in an operating systems, many concurrent processes exist : the driver code, the user programs, any background tasks etc. This does not always classify as a parallel execution unless we have multiple resources (processors) for the same.

pajamajama

Regarding the motivation for programming with threads in proxy lab: the purpose of having pthreads was to ensure that if, for example, there were two requests being made, request #2 wouldn't necessarily have to wait for request #1 to be executed completely before starting. This is important because if request #1 was downloading a movie from Amazon and request #2 was retrieving the homepage of a website, we wouldn't want to wait for an hour or two for the movie to finish downloading before being able to view the website.

Regarding parallelism vs concurrency, this is kind of how I think about it (correct me if I'm wrong):

When we are taking an exam in class, all the students are working in parallel because we are working on the exam simultaneously.

If a question has many parts to it, then the student is doing concurrent work because he or she writes the answer to one part at one time. The tasks might be interleaved if the student suddenly thinks of the answer to part 4 while doing part 3 and briefly stops to write down the answer for part 4 before going back to finish part 3's answer.

rsvaidya

I would like to reiterate what Prof. Kavyon said in class about the hypothetical case where one of the two requests blocked the total bandwidth of the network and thus both concurrency and parallelism could not have helped to service both the requests at the same time. This shows how other factors like the usage of I/O resources, memory also affect the parallelism and concurrency.

boba

I remember the difference as "parallelism is an implementation of concurrency". But not the only one since interleaving can implement concurrency without parallelism.

rc0303

My understanding is that multithreading for the Proxy is meant to prevent blocking, not necessarily to make the program faster, while multithreading in this class is meant to make our programs faster by delegating work to be executed simultaneously by different processors.

shpeefps

In 15-213 we were focused on making sure that all the threads were able to have equal access to the limited resources provided by the single core. However, when we talk about parallel programming we are talking about how to use multiple cores and maximize usage of all available resources to increase performance.

rootB

@bharadwaj, is hyper-threading (or simultaneous multi-threading) parallelism or concurrency? It utilizes one processor only, yet multiple threads can run simultaneously (doing at once). Also, instruction-level parallelism is also one kind of "parallelism". SIMD happens within a single core as well. These are the reasons I'm doubtful about the statement of "a parallel program runs on multiple processors".

bharadwaj

Good point. @paracon already stated what I wanted to say more eloquently.

Concurrency gives you tools to deal with parallelism. Parallelism is what we say when more than one instruction is executed at a time. Whether this happens on one processor or multiple processors doesn't actually matter.

jedi

Another important difference is that in proxylab, our goal was to minimise the latency for each task/web request (QoS was measured at a per-request basis).

Most of our work int this course (so far) has focused on reducing latency for a job comprising of a group of tasks. Improving the latency of individual task is less important than completing the entire job as quickly as possible.

Brandon

Concurrency is the ability to run task independently and interleave their execution where as parallel execution regards executing two or more instructions at the same time. Additionaly it has been interesting in this class to see the strong emphisis on perfomance just in terms of time for execution with no regard space efficiency - memory must be so cheap now days =)

jedi

That's true. I don't know how the course progresses, but so far all our working sets have fit comfortably within main memory, and the actual motivation for being space-efficient (so far, in this course) is to remain cache-resident.

With that in mind, we have considered space-efficiency in 2 cases, both with the primary goal of reducing latency: 1. In assignment 2, we tried hard to fit into shared memory to benefit from caching 2. This slide in Lecture 9 describes the superlinear speedup once our scaled out resources have a large enough cache for the entire working set.