views:

206

answers:

2

I have no doubt that for client applications, AsParallel() will bring some out-of-the-box performance gains. But what if I would use it in a web environment. Let's say I have a widget framework that loops over all widgets to get their data and render output. This would parallelize great no?

I do have my doubts on using AsParallel() in this scenario. What if I have a large number of visitors for my site, isn't IIS going to use multiple threads to handle all requests? Aren't there going to be locking issues presented after a while, or threads dying because all processors are in use?

It's just a thought, what do you think about this?

+2  A: 

do have my doubts on using AsParallel() in this scenario. What if I have a large number of visitors for my site, isn't IIS going to use multiple threads to handle all requests?

It is but, the as AsParallel() option will (potentially) use mutiple threads to loop over each item in the collection for that request. Potentially it will lower the response time for each request that uses it. It's difficult to say if it will help or hinder you, depending on the object collection size etc. Truthfully, you'll have to try it out to see.

Aren't there going to be locking issues presented after a while, or threads dying because all processors are in use?

It's difficult to say. This depends on how much of the server is in use at the time. If you are pegging the server at 99%, you're probably going to have problems (but then again, using the AsParallel() option is most likely going to be the least of your worries.)

Kevin
Ok, this confirms my doubts on the subject. I was planning on performing some load tests but this will only be to prove my point to my colleagues.
Bjorn Bailleul
A: 

I would actually test to see if AsParallel will get you any gains. In performance tests I've run against some code, in simple to medium cases, no real performance benefit was gained by using AsParallel (in fact, it was actually worse because of the extra overhead from creating the threads and marshalling the values).

In addition, depending on how the threads are created, you could be using more threads from your ASP.NET thread pool instead of other threads.

Tejs