views:

42

answers:

3

I've got an ASP.net page that runs a script which takes anywhere between 1 second and 10 minutes to run dependant on the parameters passed in to it.

My question is, if the server is multicore, will this script automatically make use of all the processors, or is it constricted to one.

Thanks for any help

+2  A: 

I believe each request only gets assigned one processor/thread by default. You can optimize it yourself by making multiple threads in your code to do your work (that way you might be using more processors).

You can mark your application pool to have more threads, however this will not assign more threads/processors to a single request, but will allow you to handle more requests at once (because the requests are balanced over the threads).

Gertjan
+2  A: 

No, the page will only run on one core.

IIS uses several threads to process requests, but it only uses one thread at a time for each request.

If you want the code to make use of more than one core, you have to start threads yourself.

Guffa
Thanks for that!
Tom Gullen
+1  A: 

ASP.NET is multi-threaded. So a new thread is used to handle each page request. It all depends on the workload of a given processor if the new thread is assigned to a different CPU/Core. But all of your cores are used by ASP.NET. So your app is never restricted to one CPU.

But the real question is: what is your goal? 1] Are you just afraid that your long running operations will hang ASP.NET? 2] Or do you wish to reduce the time it takes for your script to execute?

If you make your long-running-page asynchronous, then each thread will be returned immediately to the ASP.NET thread pool, which drastically increases the performance of your site. This solves problem 1.

Read up on the parallel task library extensions to see how you can more effectively use all cores to handle long running tasks. Most tasks can be divided into sub tasks which can run in parallel. This solves problem 2.

Hope this helps.

I_LOVE_MONEY
Thanks, great answer. I'm looking at reducing the total execution time. The script is one gigantic loop that sometimes recurses and evaluates hundreds of thousands of states. Do you think it would be beneficial for me to look into running mutliple threads? If I have two threads, one could start from the begining of the loop, and the other could start from the middle (this is calculable). Theoretically reducing execution speed in half?
Tom Gullen
If you are looping over a collection, where each item in the collection is independent of all others, then this would certainly be possible. But I also think that the parallel task library was created for just this kind of task. With PTL, you simply perform your loop and the library handles the splitting of each loop iteration over your available cores. So you don't need to fess around with one, two, three or even a hundred threads. It all happens auto-magically.
I_LOVE_MONEY