简体   繁体   English

使用性能监视器监视池化连接

[英]Using Performance Monitor to monitor pooled connections

I'm investigating this error from a MVC3 application that is failing under load: 我正在从负载失败的MVC3应用程序调查此错误:

"The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached." “在从池中获取连接之前已经过了超时时间。这可能是因为所有池连接都在使用中并且达到了最大池大小。”

The application is using the Repository pattern and Entity Framework, and my hunch is that it's not closing off connections properly. 该应用程序正在使用存储库模式和实体框架,我的预感是它没有正确关闭连接。 I want to be able to monitor the number of pooled connections on the SQL Server. 我希望能够监视SQL Server上的池连接数。 Searching around leads me to believe that I can use these counters in Perfmon: 搜索引导我相信我可以在Perfmon中使用这些计数器:

  • .NET CLR Data .NET CLR数据
  • .NET Data Provider for SQLServer 用于SQLServer的.NET数据提供程序

However both of them show and being disabled / grayed out. 但是它们都显示并被禁用/变灰。

I am running Perfmon directly on the server, and both ISS and SQL Server are running on the server. 我直接在服务器上运行Perfmon,并且ISS和SQL Server都在服务器上运行。 Any ideas why these counters would not be available? 有什么想法为什么这些计数器不可用?

I've also tried using SQL Profiler to monitor pooled connections, but the EventSubClass column isn't available for AuditLogin. 我还尝试使用SQL事件探查器来监视池化连接,但是EventLog子类不适用于AuditLogin。

You can run this from a SQL query windows to get a count and the details of current connections and session running on your SQL server. 您可以从SQL查询窗口运行此命令以获取计数以及SQL服务器上运行的当前连接和会话的详细信息。

select * FROM sys.dm_exec_sessions AS es  
INNER JOIN sys.dm_exec_connections AS ec  
ON es.session_id = ec.session_id

I've had trouble with pooled connections. 我在汇集连接方面遇到了麻烦。 They're hard to control. 他们很难控制。 Explicitly closing them never seemed to work since they're under the control of .NET. 显然关闭它们似乎永远不会起作用,因为它们处于.NET的控制之下。 The biggest reason we've run out of connections is uncommitted transactions. 我们用完连接的最大原因是未提交的事务。 If a transaction is left uncommitted or rolled back for some reason, the connection, instead of being re-used, get's stuck in limbo, forcing .NET to open yet another connection to continue processing. 如果某个事务由于某种原因未提交或回滚,则连接不会被重新使用,而是迫使.NET打开另一个连接以继续处理。

From the SQL side, the only viable way to review this is by setting up a login event trace. 从SQL方面来看,唯一可行的方法是通过设置登录事件跟踪。 The "Event Subclass" column will tell you if the event happened using a pooled connection or not. “事件子类”列将告诉您是否使用池化连接发生了事件。 With that, you can correlate the host, login, and application names and continue digging. 有了它,您可以关联主机,登录名和应用程序名称并继续挖掘。

Audit Login Event Class 审核登录事件类

On the application side you can use the performance counters of ".NET DATA PROVIDER FOR SQL SERVER" on perfmon. 在应用程序端,您可以在perfmon上使用“.NET DATA PROVIDER FOR SQL SERVER”的性能计数器。

Performance Counters in ADO.NET ADO.NET中的性能计数器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM