Does an ASP.net page running on IIS make use of multicore processors?
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, w开发者_JAVA技巧ill this script automatically make use of all the processors, or is it constricted to one.
Thanks for any help
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.
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).
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.
精彩评论