2015-05-19 71 views
3

後超時了一會兒一些命令我們已經在asp.net mvc的使用EF6和SQL Server 2012的SQL服務器剛剛恢復

我們有兩個環境大型Web應用程序:臨時和生產。

每當我們有一個釋放,我們首先完全相同的代碼部署到分期和恢復服務器用於測試目的生產的分貝。這一直對我們有效。

現在,當我們恢復生產的DB到我們的一些命令得到一些超時分段服務器。奇怪的是,幾個小時後,我們停止超時。


這是超時的一個的堆棧跟蹤:

[Win32Exception (0x80004005): The wait operation timed out] 

[SqlException (0x80131904): Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. 
The statement has been terminated.] 
    System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +388 
    System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +688 
    System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) +4403 
    System.Data.SqlClient.SqlDataReader.TryConsumeMetaData() +82 
    System.Data.SqlClient.SqlDataReader.get_MetaData() +135 
    System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +6664141 
    System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite) +6666008 
    System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite) +577 
    System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +107 
    System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +288 
    System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) +180 
    Glimpse.Ado.AlternateType.GlimpseDbCommand.ExecuteDbDataReader(CommandBehavior behavior) +847 
    System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch(Func`1 operation, TInterceptionContext interceptionContext, Action`1 executing, Action`1 executed) +72 
    System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.Reader(DbCommand command, DbCommandInterceptionContext interceptionContext) +306 
    System.Data.Entity.Core.Mapping.Update.Internal.DynamicUpdateCommand.Execute(Dictionary`2 identifierValues, List`1 generatedValues) +417 
    System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update() +218 

[UpdateException: An error occurred while updating the entries. See the inner exception for details.] 
    System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update() +537 
    System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction(Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess) +627 
    System.Data.Entity.Core.Objects.ObjectContext.SaveChangesToStore(SaveOptions options, IDbExecutionStrategy executionStrategy) +212 
    System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Func`1 operation) +263 
    System.Data.Entity.Core.Objects.ObjectContext.SaveChanges(SaveOptions options) +262 
    System.Data.Entity.Internal.InternalContext.SaveChanges() +218 

[DbUpdateException: An error occurred while saving entities that do not expose foreign key properties for their relationships. The EntityEntries property will return null because a single entity cannot be identified as the source of the exception. Handling of exceptions while saving can be made easier by exposing foreign key properties in your entity types. See the InnerException for details.] 
    System.Data.Entity.Internal.InternalContext.SaveChanges() +291 
    *******.Services.DbTransaction.TransactionManager.SaveChanges() in c:\BuildAgent\work\c357fed3de014622\Source\Services\*******.Services\*******.Services\DbTransaction\TransactionManager.cs:28 
    System.Web.Mvc.Async.<>c__DisplayClass48.<InvokeActionMethodFilterAsynchronouslyRecursive>b__41() +112 
    System.Web.Mvc.Async.<>c__DisplayClass48.<InvokeActionMethodFilterAsynchronouslyRecursive>b__41() +452 
    System.Web.Mvc.Async.<>c__DisplayClass48.<InvokeActionMethodFilterAsynchronouslyRecursive>b__41() +452 
    System.Web.Mvc.Async.<>c__DisplayClass48.<InvokeActionMethodFilterAsynchronouslyRecursive>b__41() +452 
    System.Web.Mvc.Async.<>c__DisplayClass33.<BeginInvokeActionMethodWithFilters>b__32(IAsyncResult asyncResult) +15 
    System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() +37 
    System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +241 
    System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +29 
    System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +111 
    System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +53 
    System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +19 
    System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +51 
    System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +111 
    System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +606 
    System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +288 

我們有一個動作過濾器,如果一切順利的請求(所以我們沒有這樣做,調用context.SaveChanges()方法在每個動作中手動)。這就是爲什麼堆棧跟蹤沒有任何操作,當操作完成時,它會在SaveChanges()調用中超時。

這個請求有很多事情發生,這就是爲什麼我沒有顯示代碼,我們正在做通常的事情:更新一些行,插入新的行等等。有一些複雜的命令,但不復雜足以讓db超時。當我們使用相同的生產分貝在我們的開發機器上運行代碼時,它運行正常。

奇怪的是,它幾個小時後停止超時。但我們不能冒這樣的風險。

現在,我知道你不可能只提供給我一個解決方案。但我想知道一些技巧,三分,諮詢,在哪裏看,什麼檢查等

編輯

我們的服務器擁有12GB的RAM和英特爾至強E5-2680 @ 2.80GHz的。

我們的網站是唯一運行在那裏的網站。

我們的數據庫小於4GB

我們不上我們的開發機得到超時。

回答

4

我們終於找到發生了什麼事:

我們這是在遷移後執行種子的方法,該方法打開數據庫的連接並且還在查詢一些永久響應的外部服務,並持續運行數小時,這些查詢阻止了插入命令。

感謝Zdravko's suggestion我們能夠找到問題。

我們運行了exec sp_who2,發現insert被種子方法的select查詢攔截。

所以,如果有人在這裏得到了類似的問題:什麼幫助我們在使用時間超過30 sec找到有問題的查詢和使用exec sp_who2檢查,如果有人阻攔他們查詢的SQL事件探查器和過濾。

3

超時很可能是由於SQL Server重建索引和其他維護作業在還原後運行。這些可能會花費大量的時間在更大的數據庫上。例如全文搜索索引需要特別長的時間來建立...

+0

喜歡幾個小時?我的意思是,上一次就像是6個小時,我們甚至運行了'exec sp_updatestats' –

+0

,這一切都取決於你的db有多大以及服務器上還有其他什麼(以及服務器在第一個地方) –

+0

我編輯我的問題 –