【问题标题】:Signalr SQL backplane causes The wait operation timed out exceptionSignalr SQL 背板导致等待操作超时异常
【发布时间】:2017-05-03 10:53:56
【问题描述】:

我们最近使用 sql server 实现了背板。我们创建背板的服务器也包含其他数据库。这些其他数据库由不同服务器上的不同应用程序访问。对于压力测试,我们实现了一个简单的信号器客户端程序,它每 30 秒向服务器发送一条消息。有两台服务器由负载均衡器处理。当客户端数量较少时,背板可以很好地工作。

问题在于客户端数量较多时。 (接近 50 或更多)。尝试将数据库服务器用于其他数据库的其他应用程序会引发以下异常。

System.Data.SqlClient.SqlException: Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding. ---> System.ComponentModel.Win32Exception: The wait operation timed out
   --- End of inner exception stack trace ---
   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   at System.Data.SqlClient.SqlDataReader.get_MetaData()
   at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
   at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds)
   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite)
   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
   at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext,TResult](TTarget target, Func`3 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)
   at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.Reader(DbCommand command, DbCommandInterceptionContext interceptionContext)
   at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
   --- End of inner exception stack trace ---
   at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
   at System.Data.Entity.Core.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext context, ObjectParameterCollection parameterValues)
   at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
   at System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClass7.<GetResults>b__5()
   at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation)
   at System.Data.Entity.Core.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
   at System.Data.Entity.Core.Objects.ObjectQuery`1.<System.Collections.Generic.IEnumerable<T>.GetEnumerator>b__0()
   at System.Data.Entity.Internal.LazyEnumerator`1.MoveNext()
   at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source)
   at System.Linq.Queryable.Count[TSource](IQueryable`1 source)

由于此异常,所有其他应用程序都因无法访问数据库而中断。如果我们禁用背板,问题会立即解决。 (停止两个信号服务器)。这是使用具有大量用户的背板时的预期行为还是背板的问题?

PS - 我们注意到抛出这些异常的机器有超过 3000 个线程分配给 w3wp.exe 进程。似乎他们被困在手术中。

【问题讨论】:

  • 您是否尝试过分析 SQL Server 并发现是否有任何需要超过 30 秒才能完成的繁重查询?任何性能调查?
  • 不幸的是,我们没有访问该数据库机器的权限,但是当我们禁用背板时,获得超时异常的相同查询可以正常工作。
  • 通常情况下,背板不会造成任何麻烦。此外,SQL server 能够承受更大的工作量。你检查过连接和发送消息的数量吗?
  • 我们发现其他应用服务器(不是signalr服务器)中的w3wp.exe分配了3000多个线程。好像他们被困在一个手术中。
  • 当然,您应该有机会分析服务器的活动。否则几乎不可能提供任何帮助。

标签: c# sql asp.net signalr signalr-backplane


【解决方案1】:

如果您不使用异步调用,那么其中一个消息线程花费的时间比预期的要长,并且在它等待返回时另一个线程被卡住并且您基本上被线程锁定。

我能想到的两种可能的解决方案是:

1) 确保您正在对数据库进行异步调用。

2) 确保您在 IIS 服务器上设置了足够的线程。您至少需要 12 个,默认设置通常只有 1 个。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-02
    • 2019-03-13
    • 1970-01-01
    • 1970-01-01
    • 2016-10-20
    相关资源
    最近更新 更多