Dan*_*ola 31 connection timeout sql-server-2008 connection-timeout
我有一个托管我的网站的服务器几乎没有流量.
一些人(<20)每天进入该网站,一些RSS阅读器订阅了我们推出的一些提要.
几乎每天晚上,一个RSS阅读器都会在半夜打电话给我们,并且由于连接中的超时而导致网站无法连接到SQL Server.细节非常奇怪,所以我正在寻找一些可能出现问题的帮助,因为我不知道从哪里开始寻找.
我们在Windows Server 2008上使用ASP.Net MVC,实体框架和SQL Server 2008.这台机器是我们从一个不完全顶级的提供商那里获得的专用盒子,所以事情可能是非最佳配置,或者谁知道什么其他.
盒子也很小,只有1Gb的RAM,但它应该承担我们现在的那种负载......
我正在复制下面的完整调用堆栈,但首先,我们知道的一些事情:
更新:我们按照建议添加了一个分析器,在我们遇到新的异常之前花了很长时间.这是我们所知道的新内容:
所以,简而言之,我对这一点完全无能为力.我无法找到那些快速连续运行的数百个查询的原因,但我相信这些问题必须与问题有关.
我也不知道如何诊断连接问题...
或者如果Profiler跟踪可能会丢失一些根据IIS进行的查询...
有任何想法吗?
这是例外信息:
System.Data.SqlClient.SqlException: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
System.Data.EntityException: The underlying provider failed on Open. ---> System.Data.SqlClient.SqlException: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
at System.Data.SqlClient.SqlConnection.Open()
at System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure)
at System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure)
--- End of inner exception stack trace ---
at System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure)
at System.Data.EntityClient.EntityConnection.Open()
at System.Data.Objects.ObjectContext.EnsureConnection()
at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
at System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator()
at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source)
at System.Data.Objects.ELinq.ObjectQueryProvider.<GetElementFunction>b__1[TResult](IEnumerable`1 sequence)
at System.Data.Objects.ELinq.ObjectQueryProvider.ExecuteSingle[TResult](IEnumerable`1 query, Expression queryRoot)
at System.Data.Objects.ELinq.ObjectQueryProvider.System.Linq.IQueryProvider.Execute[S](Expression expression)
at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable`1 source)
at MyProject.Controllers.SitesController.Feed(Int32 id) in C:\...\Controller.cs:line 38
at lambda_method(ExecutionScope , ControllerBase , Object[] )
at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClassa.<InvokeActionMethodWithFilters>b__7()
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName)
at System.Web.Mvc.Controller.ExecuteCore()
at System.Web.Mvc.MvcHandler.ProcessRequest(HttpContextBase httpContext)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
Run Code Online (Sandbox Code Playgroud)
任何想法都将受到极大的赞赏.
RBa*_*ung 51
这很可能是一个内存问题,可能是由其他事情加剧或触发,但仍然存在内存问题.还有另外两个(不太可能)的可能性,你应该首先检查和消除(因为它很容易这样做):
您可能已启用"自动关闭":自动关闭可能具有此行为,但很少打开它.要检查这一点,请在SSMS中右键单击应用程序数据库,选择"属性",然后选择"选项"窗格.查看"自动关闭"条目并确保将其设置为False.还检查tempdb.
SQL代理作业可能会导致它:检查代理的历史记录日志以查看在事件期间是否有任何一致的作业.请记住检查维护作业,因为重建索引等常常在运行时被引用为性能问题.现在这些候选人不太可能,只是因为他们通常不会受到Profiler的影响.
如果那些没有显示任何内容,那么你应该检查内存问题.我怀疑Memory是你原因的原因,因为:
你有1 GB的内存:虽然这在技术上高于SQL Server的最低值,但它远低于SQL Server的建议,并且低于我的生产经验,即使对于负载较轻的服务器也是如此.
您在同一个盒子上运行IIS和SQL Server:这本身不是推荐的,很大程度上是因为争用内存的结果,但只有1 GB的内存导致IIS,应用程序,SQL Server,操作系统和任何其他任务和/或维护都在争取很少的内存.Windows管理它的方式是通过积极地将其从非活动进程中取出来为活动进程提供内存.对于像SQL Server这样的大型进程,可能需要几秒甚至几分钟才能获得足够的内存,以便能够在这种情况下完全为请求提供服务.
Profiler使90%的问题消失了:这是一个很大的线索,内存可能是问题所在,因为通常情况下,像Profiler这样的东西对这个特定问题产生了这种影响:Profiler任务使SQL Server保持一点点活跃的时间.通常,这只是足够的活动,要么让它远离操作系统的"清道夫"列表,要么至少在某种程度上降低它的影响.
关闭Profiler:它对问题产生海森堡影响,因此您必须将其关闭,否则您将无法可靠地看到问题.
从另一个框运行系统监视器(perfmon.exe),该框远程连接到运行SQL Server和IIS的框上的perfomrance集合服务.您可以通过首先删除三个默认统计信息(它们只是本地),然后添加所需的统计信息(如下)来轻松完成此操作,但请确保在第一个下拉列表中更改计算机名称以连接到SQL框.
通过在perfmon上创建"计数器日志"将收集的数据发送到文件.如果您对此不熟悉,那么最简单的方法可能是将数据收集到选项卡或逗号分隔文件中,您可以使用Excel打开该文件进行分析.
设置perfmon以收集到文件并向其添加以下计数器:
- 处理器\%处理器时间[总计]
- PhysicalDisk \%空闲时间[ 对于每个磁盘 ]
- PhysicalDisk\Avg.磁盘队列长度[ 对于每个磁盘 ]
- 记忆\页数/秒
- Memory\Page Reads/sec
- 记忆\可用MBytes
- 网络接口\字节总数/秒[ 对于每个使用的接口 ]
- 处理\%处理器时间[ 见下文 ]
- Process\Page Faults/sec [ 见下文 ]
- 流程\工作集[ 见下文 ]
对于进程计数器(上面),您希望包括sqlserver.exe进程,任何IIS进程和任何稳定的应用程序进程.请注意,这仅适用于"稳定"流程.根据需要不断重新创建的进程无法以这种方式捕获,因为在它们存在之前无法指定它们.
在问题最频繁发生的时间内将此集合运行到文件.将收集间隔设置为接近10-15秒.(这会收集大量数据,但您需要此解决方案来挑选单独的事件).
发生一个或多个事件后,停止收集,然后使用Excel打开收集的数据文件.您可能需要重新格式化时间戳列以便有用地显示,并显示小时分钟和秒.使用您的IIS日志查找事件的确切时间,然后查看perfmon数据以查看事件发生前后的情况.特别是你想看看它的工作集之前是否很小,之后很大,之间有很多页面错误.这是这个问题最明显的迹象.
将IIS和SQL Server分隔到两个不同的框(首选),或者在框中添加更多内存.我认为3-4 GB应该是最低限度.
这里的问题是它很可能是外围的,或者只是对你的主要问题有所贡献.请记住,Profiler使90%的事件消失了,所以剩下的可能是一个不同的问题,或者它可能只是问题的最极端的恶化者.由于它的行为,我猜它要么循环其缓存,要么还有其他应用程序服务器进程的后台维护.
| 归档时间: |
|
| 查看次数: |
28693 次 |
| 最近记录: |