【问题标题】:application_start firing unexpectedly asp.netapplication_start 意外触发 asp.net
【发布时间】:2010-10-07 05:48:10
【问题描述】:

我正在查看一个 asp.net 应用程序,该应用程序在 global.asax 内部开始调用应用程序内的数据库。这些调用运行大约需要 3 秒(取决于 SQL 缓存计划)。当我第一次重新部署时,我注意到应用程序运行缓慢。我把它归结为应用程序启动时对数据库的调用。然而,几分钟后,应用程序再次需要时间来加载。

为了了解发生了什么,我已经写入了一个日志文件(见下文)。从这个文件中,您可以看到当多个请求第一次命中应用程序时,应用程序启动会多次触发。然后似乎 application_start 以随机方式触发(2-10分钟内的任何时间)。

根据我对 application_starts 工作原理的理解,它应该只在应用程序 FIRST 启动时触发,但它似乎是从多个客户端随机触发的!根据 MSDN “应用程序启动时第一次触发 Application_Start 事件。”

谁能帮我弄清楚发生了什么?我正在使用 IIS6 和 .net 2.0。这是我缺少的应用程序池设置吗?

非常感谢 瑞波

[12/02/2009 16:16:58] 91.84.25.241 - Application started, Sub MyRules started
[12/02/2009 16:17:06] 65.55.51.34 - Application started, Sub MyRules started
[12/02/2009 16:17:07] 91.84.25.241 - Application started, Sub MyRules completed
[12/02/2009 16:17:10] 65.55.51.34 - Application started, Sub MyRules completed
[12/02/2009 16:17:26] 212.115.51.229 - Application started, Sub MyRules started
[12/02/2009 16:17:30] 212.115.51.229 - Application started, Sub MyRules completed
[12/02/2009 16:17:30] 212.115.51.229 - Application started, Sub MyRules started
[12/02/2009 16:17:33] 212.115.51.229 - Application started, Sub MyRules completed
[12/02/2009 16:17:33] 212.115.51.229 - Application started, Sub MyRules started
[12/02/2009 16:17:36] 212.115.51.229 - Application started, Sub MyRules completed
[12/02/2009 16:17:36] 212.115.51.229 - Application started, Sub MyRules started
[12/02/2009 16:17:39] 212.115.51.229 - Application started, Sub MyRules completed
[12/02/2009 16:17:42] 212.115.51.229 - Application started, Sub MyRules started
[12/02/2009 16:17:48] 212.115.51.229 - Application started, Sub MyRules completed
[12/02/2009 16:17:48] 212.115.51.229 - Application started, Sub MyRules started
[12/02/2009 16:17:52] 212.115.51.229 - Application started, Sub MyRules completed
[12/02/2009 16:17:52] 212.115.51.229 - Application started, Sub MyRules started
[12/02/2009 16:17:54] 212.115.51.229 - Application started, Sub MyRules completed
[12/02/2009 16:18:27] 91.84.25.241 - Application started, Sub MyRules started
[12/02/2009 16:18:31] 91.84.25.241 - Application started, Sub MyRules completed
[12/02/2009 16:18:31] 212.115.51.229 - Application started, Sub MyRules started
[12/02/2009 16:18:33] 212.115.51.229 - Application started, Sub MyRules completed
[12/02/2009 16:29:26] 167.230.38.115 - Application started, Sub MyRules started
[12/02/2009 16:29:28] 167.230.38.115 - Application started, Sub MyRules completed
[12/02/2009 16:29:34] 82.110.42.84 - Application started, Sub MyRules started
[12/02/2009 16:29:37] 82.110.42.84 - Application started, Sub MyRules completed
[12/02/2009 16:29:38] 82.110.42.84 - Application started, Sub MyRules started
[12/02/2009 16:29:41] 82.110.42.84 - Application started, Sub MyRules completed
[12/02/2009 16:32:53] 99.142.1.97 - Application started, Sub MyRules started
[12/02/2009 16:32:57] 99.142.1.97 - Application started, Sub MyRules completed
[12/02/2009 16:32:57] 99.142.1.97 - Application started, Sub MyRules started
[12/02/2009 16:33:01] 99.142.1.97 - Application started, Sub MyRules completed
[12/02/2009 16:33:01] 99.142.1.97 - Application started, Sub MyRules started
[12/02/2009 16:33:06] 99.142.1.97 - Application started, Sub MyRules completed
[12/02/2009 16:33:06] 99.142.1.97 - Application started, Sub MyRules started
[12/02/2009 16:33:10] 99.142.1.97 - Application started, Sub MyRules completed
[12/02/2009 16:33:11] 99.142.1.97 - Application started, Sub MyRules started
[12/02/2009 16:33:16] 99.142.1.97 - Application started, Sub MyRules completed
[12/02/2009 16:36:15] 65.55.51.34 - Application started, Sub MyRules started
[12/02/2009 16:36:17] 65.55.51.34 - Application started, Sub MyRules completed
[12/02/2009 16:41:37] 119.123.226.156 - Application started, Sub MyRules started
[12/02/2009 16:41:37] 62.49.121.122 - Application started, Sub MyRules started
[12/02/2009 16:41:40] 62.49.121.122 - Application started, Sub MyRules completed
[12/02/2009 16:41:40] 119.123.226.156 - Application started, Sub MyRules completed
[12/02/2009 16:41:41] 62.49.121.122 - Application started, Sub MyRules started
[12/02/2009 16:41:44] 62.49.121.122 - Application started, Sub MyRules completed
[12/02/2009 16:45:17] 84.70.249.242 - Application started, Sub MyRules started
[12/02/2009 16:45:19] 84.70.249.242 - Application started, Sub MyRules completed
[12/02/2009 16:47:03] 80.41.121.68 - Application started, Sub MyRules started
[12/02/2009 16:47:05] 80.41.121.68 - Application started, Sub MyRules completed
[12/02/2009 16:47:29] 81.179.26.249 - Application started, Sub MyRules started
[12/02/2009 16:47:31] 81.179.26.249 - Application started, Sub MyRules completed
[12/02/2009 16:47:59] 81.136.179.170 - Application started, Sub MyRules started
[12/02/2009 16:47:59] 81.136.179.170 - Application started, Sub MyRules started
[12/02/2009 16:48:02] 81.136.179.170 - Application started, Sub MyRules completed
[12/02/2009 16:48:02] 81.136.179.170 - Application started, Sub MyRules started
[12/02/2009 16:48:02] 81.136.179.170 - Application started, Sub MyRules completed
[12/02/2009 16:48:02] 81.136.179.170 - Application started, Sub MyRules started
[12/02/2009 16:48:04] 81.136.179.170 - Application started, Sub MyRules completed
[12/02/2009 16:48:04] 81.136.179.170 - Application started, Sub MyRules completed
[12/02/2009 16:52:35] 69.34.161.80 - Application started, Sub MyRules started
[12/02/2009 16:52:35] 69.34.161.80 - Application started, Sub MyRules started
[12/02/2009 16:52:35] 69.34.161.80 - Application started, Sub MyRules started
[12/02/2009 16:52:38] 69.34.161.80 - Application started, Sub MyRules completed
[12/02/2009 16:52:38] 69.34.161.80 - Application started, Sub MyRules started
[12/02/2009 16:52:39] 69.34.161.80 - Application started, Sub MyRules completed
[12/02/2009 16:52:39] 69.34.161.80 - Application started, Sub MyRules completed
[12/02/2009 16:52:40] 69.34.161.80 - Application started, Sub MyRules completed

【问题讨论】:

    标签: asp.net global-asax web-applications


    【解决方案1】:

    检查事件日志,有些东西导致应用程序池回收。

    【讨论】:

      【解决方案2】:

      检查应用在什么情况下会重启。 最近我们正在将一些日志条目写入 bin 文件夹,并且发生了完全相同的事情,我们不明白原因。 然后终于意识到对bin文件夹进行任何修改都会导致应用重启。

      【讨论】:

      • 在过去的几个小时里,我一直在做这件事并与我的网络应用程序搏斗。感谢您在这里的回答,即使与这个问题有关的情况并不完全一样!
      • +1 - 我在那里转储了一个生成的 SQL 文件,但不知道为什么应用程序会重新启动。如果可以的话,我会再投票 1000 次。
      • 感谢您节省了长途旅行!
      【解决方案3】:

      原来是个泄露的dll……

      【讨论】:

      • 经过 5 年,它现在发生了重大泄漏......但说真的,如果我没记错的话,那是一个第 3 方重写 dll,其中有一个错误,并且引发了导致应用程序回收的错误连续……记不住细节
      • 有问题的第三方 dll 就是! =)
      • 我对你投了反对票,因为这是一个模糊无用的答案,对任何人都没有帮助。
      • 是的,我阅读了第二条评论。仍然是一个无用的愚蠢答案,对任何人都没有帮助。
      • 你问了一个问题。很抱歉,答案不是您想要的。
      【解决方案4】:

      我在多次调用 Application_Start 时遇到问题,事实证明这是因为我设置了多个实例。愚蠢的错误,但我想指出它。

      【讨论】:

        【解决方案5】:

        我不知道为什么,但我在日志中看到了同样的事情。可能是因为它花费的时间太长并且您同时有多个请求?无论如何,为了安全起见,我添加了这段代码:

        public class MvcApplication : HttpApplication
        {
            private static volatile bool hasRegisteredBgTasks = false;
            private static object registeredBgTasksLock = new object();
        
            protected void Application_Start()
            {
                lock (registeredBgTasksLock)
                {
                    if (hasRegisteredBgTasks)
                    {
                        return;
                    }
                    // Actual start up code.
                    hasRegisteredBgTasks = true;
                }
            }
        
            // Other Application methods...
        }
        

        【讨论】:

        • 在我的情况下,另一种可能性是使用 web 部署到实时站点。我可能已经部署了一半,用户点击它,启动应用程序,然后更多文件进入并再次重新启动。
        猜你喜欢
        • 1970-01-01
        • 2012-09-06
        • 2015-07-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-10-28
        • 1970-01-01
        相关资源
        最近更新 更多