views:

87

answers:

3

How can MVC website benefit from the new parallelism features in .net 4? don't websites support parallelism by default since multiple users access them at the same time? Can someone clarify this?

A: 

Every request is handled in its own thread, so you get some degree of parallelism by default with ASP.Net.

When considering implementing any kind of parallelism it is important to test your code with and without parallelism. You have to make sure that the overhead of wrapping, distributing and executing each task is not greater than running the tasks in serial. It often is for most of your day-to-day loops. Parallelism is best used in computationally intensive tasks.

Daniel Dyson
A: 

Parallelism is by computer processor. Parallelism doesn't mean multiple users access the application. Parallelism is that for one request, the app can split tasks across multiple processors to do the work. So multiple users accessing the app is a factor in how the server dishes out the work, but not the core idea of parallelism.

Brian
+1  A: 

Executing tasks in parallel is especially useful for long running tasks. What constitutes a long running task might differ, but it should be longer than the overhead of spinning up and synchronizing the threads.

So, there is no particular benefit for MVC, but there is a general benefit for each request which require more things to be run in parallel.

There's an article from 2007 in MSDN Magazine which outlines some performance aspects of the parallel library.

Example 1: a user hits a page which displays two different graphs. Each graph is calculated from a dataset. Executing the calculations in parallel will benefit the overall time to render the page. (Executing parallel individual tasks)

Example 2: You need to execute some function on a list of data, And use Parallel.For to enumerate over the data and execute some code on it in parallel.

You should analyze your application and figure out which parts can be run in parallel, and then test with the new language features if it helps your application or not.

Mikael Svenson