processModel与ASP.NET进程模型

配置 Microsoft Internet 信息服务 (IIS) Web 服务器上的 ASP.NET 进程模型设置。其作用是配置IIS或IIS中的应用程序池(IIS7及以后版本)的安全性,性能,健壮性,可靠性。

processModel 节只能在 Machine.config 文件中进行设置,它影响服务器上运行的所有 ASP.NET 应用程序。Machine.config文件则位于Windows\Microsoft.NET\Framework64\{.Net Framework Version}\ConfigWindows\Microsoft.NET\Framework\{.Net Framework Version}\Config中。

其配置节内容和默认设置如下,查看各个属性的作用可参考https://msdn.microsoft.com/zh-cn/library/7w2sway1(VS.80).aspx

   

 

   

在IIS6中引入了应用程序池,在应用程序池的高级设置中就包含了processModel的设置,其中应用程序标识的配置和idleTimeout的设置在Machine.config和应用程序池高级设置中都存在,但是就以应用程序池的为准了。

如在Machine.config中设置userName和password,

    <processModel 
    userName="Administrator"
    password="111" />

 

通过任务管理器查看进程的

以及通过以下代码查看进程的用户名时均无生效

 

        string GetProcessUserName(int pID)
        {
            string text1 = null;

            SelectQuery query1 = new SelectQuery("Select * from Win32_Process WHERE processID=" + pID);
            ManagementObjectSearcher searcher1 = new ManagementObjectSearcher(query1);

            try
            {
                foreach (ManagementObject disk in searcher1.Get())
                {
                    ManagementBaseObject inPar = null;
                    ManagementBaseObject outPar = null;

                    inPar = disk.GetMethodParameters("GetOwner");

                    outPar = disk.InvokeMethod("GetOwner", inPar, null);

                    text1 = outPar["User"].ToString();
                    break;
                }
            }
            catch
            {
                text1 = "SYSTEM";
            }

            return text1;
        } 

 

 

 

但是在应用程序池的高级设置中设置则生效

   

同理,设置闲置超时(idleTimeout)同样都是在应用程序池中设置才生效,在Machine.config中设置超时时间为1分钟,

<processModel
idleTimeout="1"/>

 

在应用程序池中设置为2分钟

访问站点后留意"任务管理器"中w3wp进程消失的时间,就会发现在静置两分钟后w3wp被结束掉。

经过观察还发现了其他虽然不是重名的属性,但是看其作用相似的,本人未去验证其有效性,但也列举出来

Machine.config ----------- 应用程序池

================================================

shutdownTime --------------- shutdownTImeLimit

pingInterval --------------- pingFrequency

pingResponseTime------------ pingTimeout

webGarden --------------- maxProcesses设置成大于1时

   

此外单纯出现在Machine.config配置节的属性还是会生效的,例如通过查看应用程序池的线程数量来看对maxWorkerThreadsmaxIoThreads是否会生效。

在Machine.config中添加以下设置。

    <processModel 
         autoConfig="false"
         maxWorkerThreads="1000"
         maxIoThreads="999" />

 

   

WebForm页面的Page_Load方法添加以下代码

int work,io;

ThreadPool.GetMaxThreads(out work, out io);

this.lb1.Text += string.Format("<br/> work {0} io {1}",work,io);

 

运行后发现执行结果如下

这里额外说明一下,如果autoConfig设置成true,它会自动设置maxWorkerThreadsmaxIoThreads,如需使用用户自定义设置,则需要设置成false,另外maxWorkerThreadsmaxIoThreads是单个CPU中工作线程与IO线程的数量,鄙人的电脑是双核四线程,所以实际运行出来的结果是该设置值的4倍。

关于性能这一方面鄙人参考了微软上面的一篇文章,阅读之后总结了以下几点

   

1.实际线程池的maxWorkerThreadsmaxIoThreads是配置节中

maxWorkerThreads*CPU数

maxIoThreads*CPU数

2.minWorkerThreads最好设置成 minWorkerThreads = maxWorkerThreads / 2

3.单个CPU最多处理的请求数目为 (maxWorkerThreads*number of CPUs)-minFreeThreads,minFreeThreads是httpRuntime配置节的Attribute

4.If you are making one Web service call to a single IP address from each ASPX page。Microsoft 建议您使用以下配置设置︰

 maxWorkerThreads参数和maxIoThreads参数的值设置为100

设置的maxconnection参数的值 12 *N (N是CPU数量)

设置的minFreeThreads参数的值 88 *N minLocalRequestFreeThreads参数76 *N.

•MinWorkerThreads50

   

例如,您有带四个处理器和启用超线程的服务器。根据这些公式,将本文中提到的配置设置使用下列值。

<system.web>
  <processModel maxWorkerThreads="100" maxIoThreads="100" minWorkerThreads="50"/>
  <httpRuntime minFreeThreads="704" minLocalRequestFreeThreads="608"/>
</system.web>
<system.net>
  <connectionManagement>
    <add address="[ProvideIPHere]" maxconnection="96"/>
  </connectionManagement>
</system.net>

 

   

   

参考文章

https://support.microsoft.com/zh-cn/kb/821268

https://msdn.microsoft.com/zh-cn/library/7w2sway1(VS.80).aspx

https://www.iis.net/configreference/system.applicationhost/applicationpools/add/processmodel

   

posted @ 2016-11-13 23:15  猴健居士  阅读(3320)  评论(0编辑  收藏  举报