2009-02-12 30 views
5

我正在查看一個asp.net應用程序,該應用程序在global.asax內啓動應用程序內的數據庫調用。這些調用需要大約3秒(取決於SQL緩存計劃)才能運行。我已經注意到,當我第一次重新部署時,應用程序緩慢地運行。我把這個放到了應用程序啓動時對數據庫的調用中。但幾分鐘後,應用程序再次需要時間加載。application_start意外啓動asp.net

要知道發生了什麼,我寫了一個日誌文件(見下文)。從這個文件中你可以看到,當多個請求第一次遇到應用程序時,應用程序開始多次啓動。然後看起來,application_start是以隨機方式觸發的(2-10分鐘的任何事情)。

根據我對application_starts的工作原理的理解,它只能在應用程序FIRST啓動時觸發,但它似乎是隨機從多個客戶端觸發的!根據MSDN 「Application_Start事件在應用程序啓動時第一次被觸發。」

任何人都可以幫我弄清楚發生了什麼事嗎?我使用IIS6和.net 2.0。它是我缺少的應用程序池設置嗎?

非常感謝 Rippo

[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 

回答

0

它原來是一個漏水的DLL ...

2

檢查事件日誌,一些導致應用程序池回收。

15

檢查應用程序重新啓動的情況。 最近我們正在寫一些日誌條目到bin文件夾中,並且發生了完全相同的事情,我們不明白原因。 然後終於意識到,對bin文件夾進行任何修改都會導致應用程序重新啓動。

+0

我正在這樣做,並與我的網絡應用程序在過去幾個小時摔跤。感謝這裏的答案,即使這個問題並不完全是這樣。 – 2010-05-24 20:03:28

+0

+1 - 我正在將生成的SQL文件轉儲到那裏,不知道爲什麼應用程序正在重新啓動。如果可以的話,我會再投1000次。 – TheCloudlessSky 2011-01-08 19:23:50

+0

感謝您保存長途旅行! – kalki 2013-05-07 13:13:58

2

我有一個問題,在得到的Application_Start多次調用,而且事實證明,那是因爲我有多個實例成立。愚蠢的錯誤,但我想記下它。

1

我不知道爲什麼,但我在我的日誌中看到了同樣的東西。這是否可能是因爲它需要很長時間,並且您有多個請求同時進入?無論如何,只是爲了安全起見,我添加了這段代碼:

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... 
}