Home > ASP.NET, Parallel Programming > .Net 4.0 Parallelism #2: Parallelism and ASP.NET

.Net 4.0 Parallelism #2: Parallelism and ASP.NET

Parallel Programming works great in client apps, but if you were to want to implement it for ASP.NET via IIS, you will have to be extremely careful.


By design, IIS is multi-threaded, and using the asp.net framework, you have the .NET framework load balancing the work requests across the worker threads.

ASP.NET Application

By hosting your application in IIS, you are already having alot of parallelism built in for you, so you need an even more compelling scenario before considering parallelism.

The general guideline is, if your server and application fits the following scenario, you can consider introducing parallelism to improve your application responsiveness.


  1. CPU load is moderate to low
  2. IO read/write is moderate to low
  3. Memory usage is moderate to low

i.e make sure server is not overloaded, otherwise adding parallelism will just overload the server further


  1. Uses high cpu (i.e when running the code, a single core is always maxed out)
  2. Uses objects which are thread safe (when in doubt refer to msdn or local help)
  3. Does not have dependencies on objects which are being processed (e.g data item 2 depends on some output of data item 1)


As a developer, your role is very crucial for the success of parallelism. First you must learn and understand the whole concept of parallelism. Secondly you need to understand your code and think of which sections of code is suitable candidates for performing parallelism. Thirdly decompose the problems and implement the changes. Finally and most important of all, profile your code (via perfmon, ant profiler) to make sure that it runs faster than before.

Problem Decomposition

This is the process where you evaluate the code block  and see if you can break it down into smaller chunks, common examples include foreach, and for loops.

There are 2 types of problem decomposition

1. Data Decomposition: This is where you find yourself applying the same operation to a single collection of strongly typed data. (Strongly typed is in bold because parallelism only works for strongly typed collections). One example is a foreach loop iterating thru all the records in a linq query.

so now instead of doing foreach(var item in items) {…} , you can use the parallel.foreach(items, item => {…})

nb: Parallel.ForEach has many overrides, which i will discuss in a further blog post.

2. Task Decomposition: This is where you find yourself running several smaller tasks in a bigger enclosing task and these smaller tasks themselves are independent of each other.

Since these tasks are independent of each other (strictly it does not really matter even if there are dependencies, you just have to manage them well), you can use Task.Factory.StartNew(() =>{…});

  1. March 6, 2010 at 11:26 pm

    nice tuto in here , good introduction , look at mine in my website righ here http://help.uk.cm.

    hear from you soon thanks

  1. February 18, 2010 at 9:11 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: