The entire process of HTTP request processing

Source: Internet
Author: User

One, the server accepts the actual process of HTTP requests

Two, when the client sends a request over the network to the server, HTTP. SYS will listen to the current HTTP request in real time in kernel mode. The HTTP. SYS feature is described below:

HTTP. SYS is a core component of the operating system located in Win2003 and WinXP SP2.

Enables any application to communicate with the HTTP protocol through the interface it provides.
Warm tip: If the user accidentally deleted the driver file, do not worry, the driver will be rebuilt at the next system startup. is a deleted system core components! The utility ends the drive and the driver is re-created immediately (only the shredding file cannot be rebuilt immediately, but after shredding, the next boot will be rebuilt).
Microsoft introduced the new HTTP API and kernel mode driver. SYS in Windows 2003 server to make the HTTP service-based program more efficient. The direct payoff for this change is IIS 6.0 and ASP.
In fact, after Windows XP installed SP2, HTTP. SYS is already in the system, but in fact, the operating system does not really use this kernel-level driver, and XP on the own IIS 5.1 also does not use the Http API.
The most important changes in the new HTTP API are encapsulated in the kernel mode driver. sys. Prior to this, HTTP protocol-based programs were run under User mode, and they had to handle issues such as software interrupts, context switch, thread scheduling, and so on, and often had no free access to system resources. In the past, HTTP servers such as IIS, Apache, etc. were using the Winsock API to create a network listener under User mode. The Network listener usually alone (i.e.: per application or per thread basis) occupies an IP port. Popular point is that at the same time only one application can listen to a port, which in some cases is a less comfortable limit.
The benefits of the new HTTP. Sys are broadly as follows:
1. Cache-Static content is now cached in kernel mode, which enables faster service response times
2. Logging (log)-iis's log function is faster and more standardized
3. Bandwidth control-greater scalability control and throttling
4. Reliability-All service requests are queued in HTTP. SYS instead of handled by the service program itself, so that requests that have not been processed will not be lost even if the service program restarts.
5. IP Port Reuse-Now you can allow multiple programs to listen at the same time, as long as the ports managed by HTTP. SYS (basically including those well-known ports, such as 80).

HTTP. SYS is a new listener used by IIS 6.0. Before IIS 6.0 appears, Inetinfo.exe completes the ability to listen for HTTP requests and forwards requests to the corresponding handlers. Starting with IIS 6.0, the listener is separated from the Inetinfo.exe, Inetinfo.exe is running in user mode, and HTTP. SYS completes the ability to listen for requests in kernel mode.

1. kernel mode and user mode

In Windows Server 2003, a process can run either in kernel mode or in user mode. If a process runs in kernel mode, the process can access all hardware and system data, and if a process runs in user mode, the process does not have direct access to the hardware and restricts access to system data. In the Intel processor architecture, kernel mode runs within ring 0, while user mode runs on Ring 3. By running HTTP. sys in kernel mode, the listener can access the TCP/IP protocol stack directly, but can be located outside the WWW service so that it is not affected by code flaws in the application and does not cause problems due to application crashes.

By running in kernel mode, HTTP. SYS gets a higher priority, and responds faster to the request than the previous version of IIS. HTTP. SYS improves IIS performance not only because it has a high priority, but also to queue requests while waiting for the application to respond, even if the application has stopped responding. In IIS 6.0, each application pool has a kernel-mode queue, and HTTP. SYS can forward requests to the appropriate queue. So, in IIS 6.0, when we tune performance, we can separate the load-heavy applications into different application pools, so that the less-loaded applications don't have to share the same queue with the heavier-load applications. For each application pool, the queue size is configurable.

HTTP. SYS can cache the request and, as far as possible, complete the requested service in kernel mode. If the response of a request has already been cached, then IIS does not have to re-process the request, and HTTP. sys only needs to take the response out of the cache, bypassing all IIS features, thus avoiding the need to re-process it. These cached requests are kept in memory and are not allowed to be swapped out, so increasing system memory as much as possible is a simple and effective way to improve IIS performance.

Increasing the system memory as much as possible can also reduce the number of inetinfo.exe disk exchanges. The Inetinfo.exe is run in user mode and can be swapped to disk space if necessary. If the system has too little memory, the performance of IIS will drop sharply.

2. Other HTTP. SYS Features

HTTP. SYS is also able to handle TCP/IP connections, including creating connections and disconnecting from them. Because HTTP. SYS runs directly above the TCP/IP protocol stack, it also needs to handle connections and timeouts, as well as connection limits and insufficient bandwidth. In addition, HTTP. SYS also needs to process logs.

HTTP. SYS improves the performance of IIS 6.0 by performing two important functions. First, HTTP. SYS caches requests in kernel mode, so in order to service a request, if the requested content of the request has recently served a previous request (whether it is providing static content or providing dynamic content), then it is possible to provide the requested content directly in kernel mode for that request. You do not need to switch to user mode to run in the Inetinfo.exe process.

HTTP. SYS can also queue requests to complete the requested service by the appropriate worker process. Each application pool has its own queue, and the size of the queue can be configured so that we can tune the performance of a particular application pool. Another advantage of using queues for applications that can fail is that requests for failed applications remain in the queue until the total number of requests saved in the queue reaches the upper limit of the queue. These requests can still be processed when the application is able to respond again, and the response time can be reduced by automatically restarting the failed application pool, which, in the view of the user, is only slightly delayed.

Third, how does HTTP. sys know which application pool the current request is for?????

When the implementation engineer creates the application pool, it registers the corresponding application pool ID into the registry, which is inside HTTP. sys. Then HTTP. SYS is sent to the corresponding application pool based on the current request.

IV, how IIS Handles

Web Server VS Web application

Before we understand how IIS handles ASP. NET requests, we have to be clear about the boundaries between Web services and Web applications. The relationship between a Web server and a Web application is just like the relationship between an operating system and a normal desktop application-one that provides a running environment and a real-world business function implementation. Briefly, one is host host, and one is application application. The operating system can provide a running environment for a wide variety of applications, and a Web server is a targeted application host built on the operating system (for Web applications), just like a Windows service. Yes, if you know more about Windows services than Web servers, it's a good idea to use the analogy method to learn about Web servers through Windows services (in fact, it might be a bit more sensible to use Web services instead of Web servers to express However, it is easy to confuse Web services with. NET Web Service technology.

IIS (Internet information Services)

In the Chinese operating system, IIS is known as the Internet Information Service -This is a WEB server provided by Microsoft Corporation that runs on top of the Windows operating system, and its functionality is not only capable of processing ASP. However, this article attempts to explain how IIS handles ASP. NET requests, so we can assume that "IIS is for ASP."

How IIS handles ASP. NET Requests

As a Web server, the primary task of IIS is to receive requests and distribute requests to different application pools through the Web Management Service (Web admin services,was).

After the application pool receives the request, the request is served to a worker process (w3wp.exe) based on the current health, and the worker process selects and loads the specific ISAPI (Internet Server application) based on the related attributes of the request URL (such as suffix aspx) Programming Interface, Network Service Application programming Interface).

The ISAPI for ASP. Aspnet_isapi.dll, which constructs a HttpRuntime as an application entry , starting from here, the request will go back and forth through a sequence of HttpApplication HttpModule and HttpHandler, and then respond.

Aspnet_isapi.dll

. NET programmers should be aware that the. NET Framework must be installed to run ASP. But sometimes when the. NET Framework is installed, Web sites deployed on IIS do not access properly, and then toss them online, finally running aspnet_regiis and setting up the. NET Framework version of the application pool for normal access. Yes, the purpose of running aspnet_regiis is to register the appropriate version of the. NET Framework with IIS , and if you are installing IIS first, then the. NET Framework is not so complicated ——. NET Framewo RK will automatically register.

When the. NET Framework is registered to IIS, the appropriate Isapi--aspnet_isapi.dll is added to IIS.

How IIS knows which request to distribute to which application pool

The IIS kernel module (Kernel Mode) contains an HTTP. SYS file.

Adding an application pool to IIS generates a corresponding identity ID and is logged to HTTP. SYS (in fact, the correspondence between the URL and the application pool is recorded).

Any HTTP request from the client will trigger HTTP first. SYS. In fact, HTTP. SYS itself does not execute any code, it simply listens to the client's HTTP request. The HTTP request contains the host (or IP), port, and resource path information for the WEB site, which is url--based on the mapping, and IIS naturally knows how to distribute the request to the application pool.

The entire process of HTTP request processing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.