Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How are threads tied to requests through Http.sys, IIS and ASP.NET

Tags:

I'm currently reading a lot about node.js. There is a frequent comparison between servers using a traditional thread per request model (Apache), and servers that use an event loop (Nginx, node, Tornado).

I would like to learn in detail about how a request is processed in ASP.NET - from the point it is received in http.sys all the way up to it being processed in ASP.NET itself. I've found the MSDN documentation on http.sys and IIS a little lacking, but perhaps my google-fu is weak today. So far, the best resource I have found is a post on Thomas Marquardt's Blog.

Could anyone shed more light on the topic, or point me to any other resources?

(For the purposes of this question I'm only interested in IIS7 with a typical integrated pipeline)

like image 345
David Padbury Avatar asked Jan 29 '11 21:01

David Padbury


People also ask

How ASP Net request is processed in IIS?

How IIS process an ASP.NET Request. It all starts with the user requesting for an application resource from the Web server. HTTP. SYS which is the Kernel mode HTTP listener for the IIS 6.0 and later versions, picks up the request and passes on to the web server (IIS).

How request is handled by IIS?

IIS creates a new process. IIS will then provide the query string and other parameters that are included with the request through the environment and standard input (STDIN) handle for the process. ISAPI filters are always loaded as long as the Web service is running and a request to the server has been made.

What is the role of HTTP Sys in IIS?

By default, IIS provides HTTP. sys as the protocol listener that listens for HTTP and HTTPS requests. HTTP. sys was introduced in IIS 6.0 as an HTTP-specific protocol listener for HTTP requests.


1 Answers

From my research so far, its my understanding that when a request comes in it gets put into a kernel-mode request queue. According to this, this avoids many of the problems with context switching when there are massive amounts of requests (or processes or threads...), providing similar benefits to evented IO. Quoted from the article:

"Each request queue corresponds to one application pool. An application pool corresponds to one request queue within HTTP.sys and one or more worker processes."

So according to that, every request queue may have more than one "Worker Process." (Google cache) More on worker processes

From my understanding:

  • IIS Opens creates a request queue (see the http.sys api below)
  • A "Web Site" configured in IIS corresponds to one Worker Process
  • A Web Site/Worker Process shares the Thread Pool.
  • A thread is handed a request from the request queue.

Here is a lot of great information about IIS7's architecture

Here is some more information about http.sys.

  • HTTP Server I/O Completion Stuff
  • Typical Server Tasks

Open questions i still have:

  • How the heck does IIS change the Server header if it Uses HTTP.SYS? (See this question)

Note: I am not sure if/how a "Kernel-mode request queue" corresponds to an IO completion port, I would assume that each request would have its own but I don't know, so I truly hope someone will answer this more thoroughly. I just stumbled on this question and it seems that http.sys does in fact use IO Completion ports, which should provide nearly all of the same benifits that evented IO (node.js, nginx, lighttpd, C10K, etc...) have.

like image 140
6 revs Avatar answered Nov 01 '22 08:11

6 revs