Configuring the ASP.NET Worker Process through the 'machine.config' file

转载 2007年09月18日 15:26:00

http://www.xefteri.com/articles/show.cfm?id=14

Configuring the ASP.NET Worker Process through the 'machine.config' file

Unlike classic ASP which run in the same memory space as the IIS, the new ASP.NET runs as a process of its own. This gives us more flexibility, stability and power, especially when combined with the file. Using standard XML notation inside this file, we can attribute our process to do things that will make the Webmaster's job a lot easier. We'll take a close look at the ASP.NET process and the attributes available for us to play with.

Published: Nov 11, 2002
Tested with: ASP.NET 1.1, IIS 5.1
Category: ASP.NET
33,717 views

<script type="text/javascript"> <!-- google_ad_client = "pub-3480949677475568"; google_ad_width = 468; google_ad_height = 15; google_ad_format = "468x15_0ads_al"; //2007-03-30: Article Page Top Links google_ad_channel = "3741709143"; google_color_border = "FFFFFF"; google_color_bg = "FFFFFF"; google_color_link = "0000FF"; google_color_text = "000000"; google_color_url = "008000"; //--> </script> <script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"></script> <iframe name="google_ads_frame" marginwidth="0" marginheight="0" src="http://pagead2.googlesyndication.com/pagead/ads?client=ca-pub-3480949677475568&amp;dt=1190100108718&amp;lmt=1190100108&amp;format=468x15_0ads_al&amp;output=html&amp;correlator=1190100108687&amp;channel=3741709143&amp;url=http%3A%2F%2Fwww.xefteri.com%2Farticles%2Fshow.cfm%3Fid%3D14&amp;color_bg=FFFFFF&amp;color_text=000000&amp;color_link=0000FF&amp;color_url=008000&amp;color_border=FFFFFF&amp;ref=http%3A%2F%2Fblog.csdn.net%2FRainyLin%2Farchive%2F2007%2F07%2F29%2F1715292.aspx&amp;cc=100&amp;ga_vid=1249941961.1190100109&amp;ga_sid=1190100109&amp;ga_hid=827121238&amp;flash=9&amp;u_h=1024&amp;u_w=1280&amp;u_ah=996&amp;u_aw=1280&amp;u_cd=32&amp;u_tz=480&amp;u_his=1&amp;u_java=true" frameborder="0" width="468" scrolling="no" height="15" allowtransparency="allowtransparency"></iframe>

Introduction

Unlike classic ASP which runs in the same memory space as the Internet Information Server (IIS), the new ASP.NET runs as a process of its own. This gives us more flexibility, stability and power, especially when combined with the <machine.config> file. Using standard XML notation inside this file, we can attribute our process to do things that will make the Webmaster's job a lot easier. We'll take a close look at the ASP.NET process and the attributes available for us to play with.

The new process: aspnet_wp.exe

With classic ASP it was almost a given that memory leaks and bad software development or hardware configurations would eventually cause the Internet Information Server (IIS) to hang and finally crash. Webmasters would get calls in the middle of the night to deal with a non-servicing web server, or they would proactively reboot the server every so often to release the memory. That's because the classic ASP process runs in the same memory space as IIS does. Things have changed though with .NET. There is now a new process that ASP.NET runs under: aspnet_wp.exe. This process can be configured through the <machine.config> file, and the settings will affect the whole server. This is a webmaster's dream come true, as you can now configure settings through this XML file, like recycling the process after some amount of time, or requests, or memory threshold, or create as many processes as you want depending on how many chips you have on your motherboard. We'll talk about the different settings and how to best use them, so that we can have a faster web server, with more up time.

This new process does not depend on IIS at all. It simply uses IIS to receive requests and then to send out the responses. Therefore, the ASP.NET process can be created or destroyed without affecting IIS at all. In fact, when you first start your computer the process is not created until after some ASP page is requested, even if the IIS starts automatically on reboot.

Task Manager window

If you open your Task Manager you will be able to see the process, along with the regular information that comes with a listing here, like the Process ID number, the CPU usage and time, and total memory being used by it.

The file

On a typical installation, the <machine.config> file is located at C:/WINNT/Microsoft.NET/Framework/v1.0.3705/CONFIG/machine.config. The way to configure the ASP.NET process is through the processModel tag in this file. The tag looks like this with its default settings:

1 <?xml version="1.0" encoding="UTF-8"?>
2 <configuration>
3     <system.web>
4         <processModel
5             enable="true"
6             timeout="Infinite"
7             idleTimeout="Infinite"
8             shutDownTimeout="00:00:05"
9             requestLimit="Infinite"
10             requestQueueLimit="5000"
11             restartQueueLimit="10"
12             memoryLimit="40"
13             webGarden="false"
14             cpuMask="0xffffffff"
15             userName="System"
16             password="autogenerate"
17             logLevel="Errors"
18             clientConnectedCheck="00:00:05"
19             comAuthenticationLevel="Default"
20             comImpersonationLevel="Default"
21             responseDeadlockInterval="00:03:00"
22             responseRestartDeadlockInterval="00:09:00"
23             maxWorkerThreads="25"
24             maxIoThreads="25"
25             serverErrorMessageFile=""
26             pingFrequency="00:00:30"
27             pingTimeout="00:00:05"
28         />
29     </system.web>
30 </configuration>
 

The complete documentation on the processModel tag can be found at Microsoft. You can take a close look at it on their site, but here is a summary of the attributes available within this tag:

# Attribute Settings Default
1. enable true | false true
2. timeout Infinite | HH:MM:SS Infinite
3. idleTimeout Infinite | HH:MM:SS Infinite
4. shutDownTimeout HH:MM:SS 00:00:05
5. requestLimit Infinite | int Infinite
6. requestQueueLimit int 5000
7. restartQueueLimit int 10
8. memoryLimit int 40
9. webGarden true | false false
10. cpuMask bit mask 0xffffffff
11. userName user | System | Machine System
12. password autogenerate | password autogenerate
13. logLevel All | None | Errors Errors
14. clientConnectedCheck HH:MM:SS | Infinite 00:00:05
15. comAuthenticationLevel Default | None | Connect | Call | Pkt | PktIntegrity | PktPrivacy Default
16. comImpersonationLevel Default | Anonymous | Identify | Impersonate | Delegate Default
17. responseDeadlockInterval Infinite | HH:MM:SS 00:03:00
18. responseRestartDeadlockInterval Infinite | HH:MM:SS 00:09:00
19. maxWorkerThreads int 25
20. maxIoThreads int 25
21. serverErrorMessageFile filename ---
22. pingFrequency HH:MM:SS 00:00:30
23. pingTimeout HH:MM:SS 00:00:05

Enabling the ASP.NET process

1 ...
2 <processModel
3     enable="true"
4 ...

The enable attribute is the most important one, because it decides if the ASP.NET process runs on its own or under IIS. The default is true, meaning that it runs on its own. This is the best option, as it allows us to reap the benefits of a separate configurable process. If it is set to false, then the rest of the settings here do not matter as they are ignored. Keep in mind that if you change this option either way, you will have to stop and restart IIS for it to take effect.

Recycling the process

There are 5 ways to recycle the ASP.NET process.

1 ...
2 <processModel
3     timeout="168:00:00"
4 ...

The first involves the timeout attribute, which simply creates a new process after the amount of time specified as a value. For example, the above setting will automatically start a new process after 168 hours, or one week. The time clock starts right after the first request is made, because the process is actually created when the first request to the ASP.NET engine is made. This setting can be extremely useful in scenarios where there is a slow leak in memory and performance, and periodic IIS resets are needed.

1 ...
2 <processModel
3     requestLimit="10000"
4 ...

A second way is to use the requestLimit attribute and give it an Integer value. A value of 10,000 like above, will start a new process after 10,000 requests have been made. This can be useful if our web server's performance degrades after a set number of requests, instead of simply some amount of time past.

1 ...
2 <processModel
3     memoryLimit="50"
4 ...

A third way is to let your system watch how much memory the process is consuming. In the above example, the attribute memoryLimit is set to 50, which means that if the process uses more than 50% of total system memory then the process is killed , a new one is created and all existing requests are reassigned to the new one. This is extemely helpful is cases where a memory leak is present, no matter how slow the leak is.

1 ...
2 <processModel
3     responseDeadlockInterval="00:03:00"
4 ...

A fourth way of doing this is by using the responseDeadlockInterval attribute. The time setting above of 3 minutes will restart the process if two things happen: there are requests in the queue, but there have not been any responses for the last 3 minutes.

1 ...
2 <processModel
3     pingFrequency="00:00:30"
4     pingTimeout="00:00:05"
5 ...

The fifth and last way of recycling the process, is to use the pingFrequency and pingTimeout attributes in conjunction. The system pings the ASP.NET process at the pingFrequency interval, and restarts it if there is no response within the pingTimeout time interval.

Shutting down the process

There are 2 ways of shutting down the ASP.NET process.

1 ...
2 <processModel
3     idleTimeout="00:30:00"
4 ...

The first way of doing it is by using the idleTimeout attribute. If the server has not served any requests for the amount of time that we specify here, then it automatically shuts down the process. If a new one comes in after that, a new process is started automatically. The example shown will shut down the existing process after 30 minutes of inactivity. This might be useful if you have long times of inactivity, for example during the early hours of the morning, and you want to use the system resources for other tasks during those times, such as database stored procedures, or email chunking.

1 ...
2 <processModel
3     shutDownTimeout="00:00:05"
4 ...

The second way is by using the shutDownTimeout attribute. This is used as a last resort, when the ASP.NET process tries to gracefully shut down and it fails. In that case, after the time that we set here has passed, a low level kill command is called on the process to make sure it is killed. This is useful in those cases where the process has crashed and is not responding anymore. The setting above will force a kill after 5 seconds.

Reducing the queue: checking if the client is still connected

1 ...
2 <processModel
3     clientConnectedCheck="00:00:05"
4 ...

Users can get impatient. If our web server is slow to respond to their requests, they might click on the same link many times. Even if only the last request is finally returned to them, the server still processes all the previous ones. That's wasted server resources. Even worse, the user might abandon their session with our server, but the server still has a queue from that user. One way we can help our server, is to have it check requests in the queue and throw away the ones which the client is no longer connected with them. In the example above, the server will check each request every 5 seconds after it has entered the queue, to see if the user who made it is still connected. If the user is not, the server throws away that request.

Conclusion

We have seen how ASP.NET now works as a separate worker process, and the benefits that can give us. We've also seen how to best use the process by attributing it through the <machine.config> file. I encourage you to take a closer look at the rest of the other attributes not mentioned in detail here, as they might be beneficial to you depending on your circumstances.

 

http://msdn2.microsoft.com/zh-cn/library/bakfs900(VS.80).aspx

如何:以用户帐户运行 aspnet_wp.exe

 

本主题适用于:

Visual Studio 版本

Visual Basic

C#

C++

J#

Visual Web Developer

速成版

标准版

专业团队版

要设置计算机从而以用户帐户运行 ASP.NET 辅助进程,请执行下列步骤。

Note注意

显示的对话框和菜单命令可能会与“帮助”中的描述不同,具体取决于现用设置或版本。若要更改设置,请在“工具”菜单上选择“导入和导出设置”。有关更多信息,请参见 Visual Studio 设置

过程

以用户帐户运行 aspnet_wp.exe

  1. 打开 machine.config 文件,该文件位于计算机上安装运行库的路径下的 CONFIG 文件夹中。

  2. 查找 <processModel> 节并将 userpassword 属性更改为要使 aspnet_wp.exe 在其下运行的用户帐户的名称和密码。

  3. 保存 machine.config 文件。

  4. 在 Server 2003 上,默认情况下已安装 IIS 6.0。相应的辅助进程是 w3wp.exe。若要在 IIS 5.0 模式中将 aspnet_wp.exe 作为辅助进程运行,必须执行下列步骤:

    1. 从“开始”菜单中单击“管理工具”,然后选择“Internet 信息服务”。

    2. 在“Internet 信息服务”对话框中,右击“网站”文件夹并选择“属性”。

    3. 在“网站属性”对话框中选择“服务”。

    4. 选择“以 IIS5.0 隔离模式运行 WWW 服务”。

    5. 关闭“属性”对话框和“Internet 服务管理器”。

  5. 打开 Windows 命令提示窗口,通过运行下面的命令重置服务器:

    iisreset

    --或者--

    net stop iisadmin /y
    net start w3svc
  6. 查找 Temporary ASP.NET Files 文件夹,它应当位于与 CONFIG 文件夹相同的路径中。右击 Temporary ASP.NET Files 文件夹,并从快捷菜单中选择“属性”。

  7. 在“临时 ASP.Net 文件属性”对话框中,选择“安全性”选项卡。

  8. 单击“高级”按钮。

  9. 在“临时 ASP.Net 文件的高级安全设置”对话框中,单击“添加”按钮。

  10. 在“选择用户、计算机或组”对话框中,在“输入要选择的对象名称”框中输入用户名(格式为:域名/用户名),然后单击“确定”。

  11. 在“临时 ASP.Net 文件的权限项”对话框中,授予用户“完全控制”,然后单击“确定”以关闭“临时 ASP.Net 文件项”对话框。

  12. 此时将出现“安全性”对话框,询问是否确实要更改系统文件夹的权限。单击“是”。

  13. 单击“确定”以关闭“临时 ASP.NET 文件属性”对话框。

 

ASP.NET Internals – IIS and the Process Model (IIS5, IIS6)

Introduction Microsoft Active Server Pages, also known as ASP, since its first release in late ...

File Upload using jQuery AJAX in ASP.NET Web API or Http handler (AJAX上传文件通过Web API或 http handler)

AJAX上传文件通过Web API或 http handler Upload file using jQuery AJAX in ASP.NET Web API This articl...

asp.net/c# 用<input type="file" />实现文件上传,multipart/form-data

我们常用的上传文件的工具(控件),它和 不一样,在后台不能直接获取到,不能像 this.FileUpload1.PostedFile……那样去获取 而有时我们必须使用,如动态给页面添加好多个,你们后台...
  • dhfekl
  • dhfekl
  • 2013年08月03日 17:19
  • 8574

asp.net 点击一个按钮弹出对话框选择文件然后选择文件完成之后就自动上传文件 input(file)

通过控件来实现目标:点击一个按钮,然后弹出对话框让你选择文件,选择文件完成之后就自动上传,而无需再点击一个额外的按钮(例如命名为“上传”的按钮)。 说明:(1)input(file)控件的oncha...
  • ablian
  • ablian
  • 2013年09月17日 13:30
  • 1732

c# asp.net Ext file fileUpload文件上传后台Request.Files获取不到解决办法

今天在搞这个ux.fileUpload控件的时候杯具了一天,后台总是获取不到Files对象,google了一下午未果,晚上回来再试的的时候成功了,我用的版本是3.3的,用的FormPanel提交,在他...

Asp.net网站中 js通过input type="file" 上传文件

前台代码 //引用jquery.form.js文件 //ajax代码 if ($("#fl

ASP.NET中的FILE对象总结

在ASP.NET中引入了名字空间,其中文件操作对应的名字空间是System.IO。名字空间和动态链接库有些类似,但是名字空间在整个.net系统中都可以应用。在ASP.NET的页面中可以使用来引用名字空...

ASP.NET中的FILE对象总结

  • 2008年10月11日 16:09
  • 29KB
  • 下载

asp.net jquery file upload

  • 2012年10月15日 14:10
  • 79KB
  • 下载

在.Net程序中调用ObjectARX函数——Through the Interface

原文:Calling ObjectARX functions from a .NET application .Net有一个非常引人注目的功能就是它调用“传统”的非托管的C++ API。虽然我称之为“...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Configuring the ASP.NET Worker Process through the 'machine.config' file
举报原因:
原因补充:

(最多只允许输入30个字)