2015-05-19 83 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

我编辑我的问题 –