设为首页 收藏本站
查看: 696|回复: 0

[经验分享] ASP.NET Internals – IIS and the Process Model (IIS5, IIS6)

[复制链接]

尚未签到

发表于 2017-2-12 10:50:50 | 显示全部楼层 |阅读模式
Introduction
  Microsoft ActiveServerPages,also known asASP,since its first release in late 1996 provided web developers with a rich and complex framework for building web applications. As years passed its infrastructure evolved and improved so much that what is now known asASP.NETisno longer something which resembles its predecessor.ASP.NETis a framework for building web applications, that is, applications that run over the web, where the client-serverparadigm is represented mostly by a browser forwarding requests for resources of different kinds to a web server. Before the advent of dynamic server-side resource generation techniques likeCGI,PHP,JSPandASP,all web servers had to do was accept client’s requests for static resources and forward them to the requestor. When dynamic technologies started to grow up web servers became invested of greater responsibility, since they had to find a way to generate thosedynamic resources on their side and return the result to the client, a task they were not formerly built for.
  From a bird’s eye view, the interaction between client and server is very simple. Communications over the web occur viaHTTP(Hyper Text Transfer Protocol), an applicationlevel protocol which relies on TCP and IP to transmit data between two nodes connected to the heterogeneous network known as World Wide Web.
  Each dynamic server-side technology essentially leans on a particular web server implementation, andASP.NETis tightly coupled with Microsoft’s InternetInformationServer,akaIIS.
  Different servers chose different ways to generate and serve dynamic resources and what we’re going to examine is howIISdoes that, together with the path a request followsonce on the server and back to the client.
IIS and ISAPI Extensions
  As mentioned, static resources needn’t to be processed by the server; once a request for such a resource arrives, the server just retrieves its contents from thefilesystemand sends it back to the client as a stream of byte flowing on theHTTPprotocol. Static resources can be images,Javascriptfiles,css style sheets or plain old html pages. It’s clear that the server needs to know how to distinguish between static and dynamic resource, whereas the second need to be processed somehow and not just sent back to the client. That’s whereISAPIextensionsappear, whereISAPIstandsfor Internet Server ApplicationProgrammingInterface.ISAPIextensionsare modules implemented as plain old Win32 .dll, on whichIISrelies to process specific resources. Mappings betweenISAPIextensionsand files are configured via theIISsnap-in and stored in theIISmetabase, where each fileextension can be associated with a particularISAPIextension, that is, when a request for such a file arrives,IIShandlesit to the correspondingISAPIextension, confident that it will be able to handle it.
Figure 1: Configuring ISAPI extensions mappings on IIS 5.0
DSC0000.jpg

  ISAPIextensions obviously need to respect a common interface through which they can be called byIISandprovided the necessary data to elaborate the request and generate a response.
  As Figure 1 illustrates, the .asp extension is mapped to theasp.dllISAPIextension; at the time ofASPthiscomponent was in charge of performing all the tasks required to generate a response, that is, collecting information about the request, made available into theASPpage viathe Request, Response and other commonASPintrinsic objects, parsing and executing theASPpageand returning the resulting HTML.
  Actually, that was a big improvement compared to a technology like CGI, butASP.NETtakes this approach much further and introduces abstractions which totally shield the developersfrom having to care about what happens at this stage.
  Wheninstalled,ASP.NETconfiguresIIStoredirect requests forASP.NETspecific files to a newISAPIextension calledaspnet_isapi.dll.What this extension does is somewhat different then the formerasp.dllextension, which was essentially responsible just for parsing and executing the requestedASPpage.The steps taken by a genericISAPImodule to process a request are totally hidden fromIIS, thereforeISAPIextensionmay follow different paradigms in order to process requests.
Table 1: IIS Application Mappings for aspnet_isapi.dll
ExtensionResource Type
.asaxASP.NET application files. Usually global.asax.
.ascxASP.NET user control files.
.ashxHTTP handlers, the managed counterpart of ISAPI extensions.
.asmxASP.NET web services.
.aspxASP.NET web pages.
.axdASP.NET internal HTTP handlers.
  As well as the file extensions listed in Table 1, theASP.NETISAPIextension manages other file extensionswhich are usually not served to web browsers, like Visual Studio project files, source code files and config files, for example.
The ASP.NET Process Model
  So far we’ve seen that when a request for anASP.NETfile is picked up byIIS, it is passed to theaspnet_isapi.dll,which is the main entry point forASP.NETrelated processing. Actually, what theISAPIextension does dependssensibly on the version ofIISavailable on the system, and thus the process model, which is the sequence of operations performed by theASP.NETruntimeto process the request and generate a response, may vary quite a bit.
  When running underIIS5.X, all ASP.NET-related requests are dispatched by theISAPIextensionto an external worker process calledaspnet_wp.exe. TheASP.NETISAPIextension,hosted in theIISprocessinetinfo.exe, passes the control toaspnet_wp.exe,along with all the information concerning the incoming request. The communication between the two is performed via named pipes, a well known mechanism for IPC (Inter Process Communication). TheASP.NETworkerprocess performs a considerable number of tasks, together with theISAPIextension. They are the main authors of all the stuff that happens under the hoods of anASP.NETrequest.To introduce a topic which will be discussed later, take note of the fact that each web application, corresponding to a different virtual directory hosted onIIS, is executed in the contextof the same process, theASP.NETworker process. To provide isolation and abstraction from the execution context theASP.NETmodelintroduces the concept of Application Domains, in brief AppDomains. They can be considered as lightweight processes. More on this later.
  If running underIIS6, on the other side, theaspnet_wp.exeprocess is not used, in favourof another process calledw3wp.exe. Furthermore,inetinfo.exeis no longer used to forwardHTTPrequeststoISAPIextensions, although it keeps running for serving other protocols requests. A lot of other details change compared to the process model used by previous versions ofIIS,althoughIIS6 is capable of running in compatibility mode and emulate the behavior of its predecessor. A big step forward, compared to the process model used when running ontop ofIIS5, is that incoming requests are in the former handled at a lower – Kernel – level and then forwarded to the correctISAPIextension,thereby avoiding inter process communication techniques which may represent an expensive operation under a performance and resource consumption point of view. We’ll delve deeper into this topic in the following paragraphs.
IIS 5.0 Process Model
  This is the default process model available on Windows 2000 and XP machines. As mentioned it consists in theIISinetinfo.exeprocesslistening by default on the TCP port 80 for incomingHTTPrequests and queuing them into a single queue, waiting to be processed. If the request is specific toASP.NET,the processing is delegated to theASP.NETISAPIextension,aspnet_isapi.dll.This, in turn, communicates with theASP.NETworker process,aspnet_wp.exevia named pipesand finally is the worker process which takes care of delivering the request to theASP.NETHTTPruntimeenvironment. This process is graphically represented in Figure 2.
Figure 2: The IIS 5.0 Process Model
DSC0001.gif

  In Figure 2 is represented an additional element we didn’t mention yet, theASP.NETHTTPRuntime Environment.It’s not topic of this article and will eventually be explained in a follow up article, but for the sake of this discussion theHTTPRuntime Environment can be considered asa black box where all theASP.NETspecific processing takes place, all the managed code lives and developers can actually put their hands on, from the HttpRuntime straight tothe HttpHandler who will finally process the request and generate the response. This is even referred to as theASP.NETPipeline orHTTPRuntimepipeline.
  One of the interesting points of this process model is that all the requests, once handled by theISAPIextension, are passed to theASP.NETworkerprocess. Only one instance of this process is active at a time, with one exception, discussed later. Therefore allASP.NETweb applications hosted onIISareactually hosted inside the worker process, too. However, this doesn’t mean that all the applications are run under the same context and share all their data. As mentioned,ASP.NETintroducesthe concept of AppDomain, which is essentially a sort of managed lightweight process which provides isolation and security boundaries. EachIISvirtual directory is executedin a single AppDomain, which is loaded automatically into the worker process whenever a resource belonging to that application is requested for the first time. Once the AppDomain is loaded – that is, all the assemblies required to satisfy that request areloaded into the AppDomain – the control is actually passed to theASP.NETpipeline for the actual processing. Multiple AppDomains can thus run under the same process, whilerequests for the same AppDomain can be served by multiple threads. However, a thread doesn’t belong to an AppDomain and can serve requests for different AppDomains, but at a given time a thread belongs to a single AppDomain.
  For performance purposes the worker process can be recycled according to some criteria which can be specified declaratively in the machine.config file placed in the directory C:\windows\microsoft.net\Framework\[framework version]\CONFIG. These criteria arethe age of the process, number of requests served and queued, time spent idle and consumed memory. Once one of the threshold value of these parameters is reached, theISAPIextensioncreates a new instance of the worker process, which will we used from then on to serve the requests. This is the only time when multiple copies of the process can be running concurrently. In fact, the old instance of the process isn’t killed, but it is allowedto terminate serving the pending requests.
IIS 6.0 Process Model
  TheIIS6 process model is the default model on machines running Windows 2003 Server operating system. It introduces several changes and improvements over theIIS5process model. One of the biggest changes is the concept of application pools. OnIIS5.X all web applications, that is, all AppDomains, were hosted by theASP.NETworkerprocess. To achieve a finer granularity over security boundaries and personalization, theIIS6 process model allows applications to run inside different copies of a new workerprocess,w3wp.exe. Each application pool can contain multiple AppDomains and is hosted in a single copy of the worker process. In other words, the shift is from a single process hostingall applications to multiple processes hosting each an application pool. This model is also called the workerprocessisolationmode.
  Another big change from the previous model is the wayIISlistens for incoming requests. With theIIS5model, it was theIISprocess,inetinfo.exe, who was listening on a specific TCP port forHTTPrequests.In theIIS6 architecture, incoming requests are handled and queued at kernel level instead of user mode via a kernel driver called http.sys; this approach has several advantagesover the old model and is called kernel-level request queuing.
Figure 3: The IIS 6.0 process model
DSC0002.gif

  Figure 3 illustrates the principal components taking part in the request processing when using the II 6 model. Once a request arrives the kernel level device driver http.sys routes it to the right application pool queue. Each queue belongs to a specificapplication pool, and thus to a specific copy of the worker process, which next receives the request from the queue. This approach highly reduces the overhead introduced by named pipes used inIIS5model since no inter process communication is taking place, but the requests are headed to the worker process directly from the kernel level driver. This has many advantages concerning reliability, too. Since running in kernel mode, the request dispatchingisn’t influenced by crashes and malfunctions happing at user level, that is, in the worker processes. Thereby, even if a worker process crashes, the system is still capable of accepting incoming requests and eventually restarts the crashed process.
  It’s the worker process who is in charge of loading theASP.NETISAPIextension, which, in turn, loadsthe CRL and delegates all the work to theHTTPRuntime.
  Thew3wp.exeworker process, differently from theaspnet_wp.exeprocess used inIIS5model, isn’tASP.NETspecific, and is used to handle any kind of requests. The specific worker process then decides whichISAPImodulesto load according to the type of resources it needs to serve.
  A detail not underlined in Figure 3 for simplicity reasons is that incoming requests are forwarded from the application pool queue to the right worker process via a module loaded inIIS6called Web Administration Service (WAS). This module is responsible for reading worker process – web application bindings from theIISmetabase and forwarding the request tothe right worker process.
References

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-341000-1-1.html 上篇帖子: 完整解决方案:让你的IIS 支持PHP方法 下篇帖子: IIS中如何配置对php的支持
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表