ASP.NET MVC重新编译限制达到了15个HostingEnvironment,启动了关闭HostingEnvironment导致关机 [英] ASP.NET MVC Recompilation limit of 15 reached HostingEnvironment initiated shutdown HostingEnvironment caused shutdown

查看:486
本文介绍了ASP.NET MVC重新编译限制达到了15个HostingEnvironment,启动了关闭HostingEnvironment导致关机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在某些时候,代码推送后不久,我们看到我们的Web应用程序中发生了大量重启,没有任何日志记录表明存在任何问题。所以我找到了这篇文章:



当您将其增加到100时,未达到限制,因此应用程序池将在常规回收计划期间进行重新计划(默认情况下每29小时)



导致整个网站重新编译的原因列表:


  1. 默认情况下,当对顶部进行任何更改时在网站中的级别文件,整个网站被重新编译。顶级文件包括global.asax文件以及bin /和App_Code /文件夹中的所有文件。其他详细信息 - https://blogs.msdn.microsoft.com/tmarq/2007/11/01/asp-net-file-change-notifications-exactly-which-files-and-directories- is-monitored /

  2. 修改web.config

  3. 配置包含文件更改,如果 SectionInformation.RestartOnExternalChanges 属性为true



    < section name =MyAppSettingstype =System.Configuration.AppSettingsSection,System.Configuration,Version = 2.0.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3arestartOnExternalChanges = truerequirePermission =false/>


注意:



如果您希望能够更改顶级文件wi导致整个站点被重新编译,您可以将Web.config文件中编译元素的optimizeCompilations属性设置为true



参考文献:



了解ASP.Net动态汇编



重新编译的另一个常见原因是由于文件被写入源代码文件夹,例如在源代码文件夹中写入日志文件或者反之病毒试图扫描Web应用程序文件夹并可能在其中写入内容(您可以从反病毒扫描中排除Web应用程序文件夹,看看它是否有帮助)。



但要完全找到你需要捕获一个ETW跟踪并看看是什么导致重新编译。这里给出了如何做的详细解释 - https://blogs.msdn.microsoft.com/tess/2008/11/06/troubleshooting-appdomain-restarts-and-other-issues-with-etw-tracing/



此处还提到了一个已知的问题 - http://support.microsoft.com/kb/319947



链接中的相关文字


但是,当您将许多新的.aspx或.ascx
文件加载到服务器时(例如,61个文件)会出现此问题。当重新编译前15个文件时,服务器卸载
应用程序,每次
重新编译另外15个文件,直到服务器达到61.这个
导致四个应用程序重新启动,即使只需要一个。


它讨论了内存含义,因此请确保您确实启用了定期应用程序池回收。



希望这有助于


At some point, shortly after a code push, we saw numerous restarts occurring in our web application with no logging indicating an issue whatsoever. So I found this article: http://weblogs.asp.net/scottgu/433194 and we added Application_End logging, which immediately revealed this:

_shutDownMessage=Recompilation limit of 15 reached HostingEnvironment initiated shutdown HostingEnvironment caused shutdown _shutDownStack= at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo) at System.Environment.get_StackTrace() at System.Web.Hosting.HostingEnvironment.InitiateShutdownInternal() at System.Web.Hosting.HostingEnvironment.InitiateShutdownWithoutDemand() at System.Web.HttpRuntime.ShutdownAppDomain(String stackTrace) at System.Web.Compilation.DiskBuildResultCache.ShutdownCallBack(Object state) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem() at System.Threading.ThreadPoolWorkQueue.Dispatch()

Googling this error reveals surprisingly little, so we updated our web.config

 <compilation debug="false" numRecompilesBeforeAppRestart="100">

and viola! Everything back to normal. We reviewed our changes thoroughly but didn't find anything that we felt could've been the culprit.

Has anyone else encountered this or similar, or has knowledge / suspicions of what in the world could've caused this? Any feedback would be superb!

解决方案

So the application is actually getting recompiled and since the default limit is 15 after 15 recompilation the app domain/application pool recycles.

Usually you will see an event in event viewer with event id - 1305. Open IIS Manager => Application Pools =>Right Click the Application pool and go to advanced settings => Scroll down to Generate Recycle Event Log Entry and change everything to true. Also you may need to enable health monitoring to see the details in event viewer.

When you increased it to 100 the limit is not reached and hence application pool would have recyled during the regular recycle schedule (default every 29 hours)

A list of what causes whole website recompile:

  1. By default, when any change is made to a top-level file in a Web site, the whole site is recompiled. Top-level files include the global.asax file and all files in the bin/ and App_Code/ folders. Additional details here - https://blogs.msdn.microsoft.com/tmarq/2007/11/01/asp-net-file-change-notifications-exactly-which-files-and-directories-are-monitored/
  2. modifying web.config
  3. a configuration include file change, if the SectionInformation.RestartOnExternalChanges property is true

    <section name="MyAppSettings" type="System.Configuration.AppSettingsSection, System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" restartOnExternalChanges="true" requirePermission="false" />

Notes:

If you want to be able to change top-level files without causing the whole site to be recompiled, you can set the optimizeCompilations attribute of the compilation element in the Web.config file to true

References:

Understanding ASP.Net dynamic compilations

One of the other common cause for recompilation is due to a file being written to the source code folder i.e. something like writing a log file with in the source code folder or anti virus trying to scan web app folder and probably writing something into it (you can exclude web app folder from anti virus scan and see if it helps).

However to exactly find out what is causing recompilation you need to capture a ETW trace and see. A detailed explanation is given here on how to do that - https://blogs.msdn.microsoft.com/tess/2008/11/06/troubleshooting-appdomain-restarts-and-other-issues-with-etw-tracing/

Also there is a known issue around this is mentioned here - http://support.microsoft.com/kb/319947

Relevant text from the link

However, this problem occurs when you load many new .aspx or .ascx files to the server (for example, 61 files). The server unloads the application when the first 15 files are recompiled and every time another 15 files are recompiled until the server reaches 61. This results in four application restarts even though only one is required.

It talks about memory implications so make sure you do have the periodic application pool recycling enabled.

Hope this helps

这篇关于ASP.NET MVC重新编译限制达到了15个HostingEnvironment,启动了关闭HostingEnvironment导致关机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆