Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 203 Vote(s) - 3.59 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How is ASP.NET multithreaded?

#1
I've been told that ASP.NET is multithreaded by default in IIS. How is this threading achieved?

Does the server farm send different requests to different cores?

Does a single request make use of multiple cores?

More importantly, are there any advantages to adding threads to ASP.NET code if the threading is done higher up in IIS?
Reply

#2
A separate thread is usually spawned for each new request, then the operating system does processor scheduling. Unless you need to process just a few requests at a time you don't need extra threading.
Reply

#3
ASP.net uses the .Net threadpool (which is configurable)
Each request is received by one of the threads in the threadpool, until each thread is already occupied. Then requests queue at the IIS Stack, until this also spills over. From there new requests are meet with the very ugly 'Server is unavailable' message.

This is the usual 'multi-threading' story for a ASP.net website.

There are many ways to ensure scalability. The most obvious being performance testing and removing bottlenecks from your code.

ASP.net can really take advantage of multiple cores by utilizing the I/O threads for any I/O request. It makes for ugly code but fast has never been pretty.

Here is the definitive [MSDN MAG][1] post on how to do this

**UPDATE**

Well I probably attempt to answer your full question:

> "More importantly is there any
> advantage to adding threads to ASP.Net
> code if the threading is done higher
> up in IIS?"

The short answer is: It depends!
If you are waiting on a long running process, then you would be better advised to implement a nicer experience for the requesting client (i.e. Out of band AJAX calls)

if you have multiple independent tasks that need to be completed for the requesting client: then you might be better off spawning a new process to run the tasks in parallel.

If your site gets lots of traffic, then you really need to consider implementing Asynchronous patterns to better utilise your CPU


[1]:

[To see links please register here]

Reply

#4
Not only does the server farm different requests to different threads, but a single request *can* change thread during the course of life cycle. This is called *thread agility*. I'm looking for a good article explaining it...

EDIT: No definitive articles yet, but [one blog post][1] explaining some of the difficulties.

EDIT: More links from comments:

- [ASP.NET Thread Switching][2] (blog post)
- [What is an "async IO operation" in .NET?][3] (SO question; sounds irrelevant but isn't)
- [ASP.NET and System.Diagnostics tracing][4] (SO question)
- [Threading differences between IIS 6 and 7][5]


[1]:

[To see links please register here]

[2]:

[To see links please register here]

[3]:

[To see links please register here]

[4]:

[To see links please register here]

[5]:

[To see links please register here]

Reply

#5
IIS makes use of the multiple cores automatically (although you can turn it off if you so choose).

The advantage to adding threads to ASP.NET code is so that you can control your own application's inner workings and not be forced to rely on IIS to make all the decisions for you.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through