加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – Application_End应该在自动App Pool Recycle上启动吗

发布时间:2020-12-16 04:36:12 所属栏目:asp.Net 来源:网络整理
导读:我已经阅读了 this,this,this和 this以及其他十几篇帖子/博客. 我在共享主机中有一个ASP.Net应用程序,经常回收.我们使用NLog并在global.asax中使用以下代码 void Application_Start(object sender,EventArgs e) { NLog.Logger logger = NLog.LogManager.GetC
我已经阅读了 this,this,this和 this以及其他十几篇帖子/博客.

我在共享主机中有一个ASP.Net应用程序,经常回收.我们使用NLog并在global.asax中使用以下代码

void Application_Start(object sender,EventArgs e) 
{
    NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
    logger.Debug("rnrnAPPLICATION STARTINGrnrn");
}
protected void Application_OnEnd(Object sender,EventArgs e)
{
    NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
    logger.Debug("rnrnAPPLICATION_OnEndrnrn");
}

void Application_End(object sender,EventArgs e) 
{
        HttpRuntime runtime = (HttpRuntime)typeof(System.Web.HttpRuntime).InvokeMember("_theRuntime",BindingFlags.NonPublic  | BindingFlags.Static  | BindingFlags.GetField,null,null);

if (runtime == null)
    return;

string shutDownMessage = (string)runtime.GetType().InvokeMember("_shutDownMessage",BindingFlags.NonPublic  | BindingFlags.Instance  | BindingFlags.GetField,runtime,null);

string shutDownStack = (string)runtime.GetType().InvokeMember("_shutDownStack",null);

ApplicationShutdownReason shutdownReason = System.Web.Hosting.HostingEnvironment.ShutdownReason;

NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
logger.Debug(String.Format("rnrnAPPLICATION ENDrnrn_shutDownReason = {2}rnrn _shutDownMessage = {0}rnrn_shutDownStack = {1}rnrn",shutDownMessage,shutDownStack,shutdownReason));
}

void Application_Error(object sender,EventArgs e) 
{
    NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
    logger.Debug("rnrnApplication_Errorrnrn");

}

我们的日志文件中充斥着“APPLICATION STARTING”条目,但在这些自发重启期间,Application_OnEnd,Application_End和Application_Error都没有被触发.我知道他们正在工作,因为有触摸web.config或/ bin文件的条目.我们还运行了内存过载测试,并且可以触发在Application_Error中捕获的OutOfMemoryException.

我们正在尝试确定虚拟内存限制是否导致回收.我们在整个代码中添加了GC.GetTotalMemory(false),但这适用于所有.Net,而不仅仅是我们的App池,对吗?我们也试过了

var oPerfCounter = new PerformanceCounter();
oPerfCounter.CategoryName = "Process";
oPerfCounter.CounterName = "Virtual Bytes";
oPerfCounter.InstanceName = "iisExpress";
logger.Debug("Virtual Bytes: " + oPerfCounter.RawValue + " bytes");

但没有共享主机的权限.

我在开发服务器上监控了应用程序的相同请求,这些请求导致生产中的循环使用了ANTS Memory Profiler,并且似乎无法找到罪魁祸首.我们还使用dev中附带的调试器来运行它,以检查可能导致应用程序中止的衍生线程中的未捕获异常.

我的问题是这些:

>如何有效监控共享主机中的内存使用情况,以便在应用程序回收之前告诉我的应用程序消耗了多少?
>为什么不调用global.asax中的Application_ [End / OnEnd / Error]处理程序?
>我还能如何确定造成这些回收的原因?

谢谢.

编辑:根据@JaniHyyti?inen的回答

场景:
线程#1开始,然后是线程#2.线程#1达到内存限制但继续处理.线程#3开始.线程#1完成,但#1在#1达到内存限制后超过60秒处理.

游泳池然后不合情理地中止? http响应#2& #3接收(这些是AJAX调用,但我在Fiddler中遇到504错误)?
是否接受了#3的请求,或者只是在新池启动时才排队?
有没有办法知道内存限制已被击中或即将出现?

欢迎任何策略.

解决方法

iis中存在应用程序池关闭时间限制.假设这是60秒,并且在共享托管环境中存在应用程序池内存限制.您的应用程序池达到此限制,iis告诉应用程序池完成当前请求的所有工作.如果所有请求在60秒之前完成处理,则application_end将触发,应用程序池将正常关闭.但是,如果60秒仍然处理并且仍在处理请求,则IIS会感到不安并杀死应用程序池.这次没有application_end会触发.同样,不会触发任何错误事件处理程序.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读