简体   繁体   English

如何在IIS中监视.NET MySQL数据连接器的连接池

[英]How to monitor connection pooling for .NET MySQL Data Connector in IIS

I have googled a fair bit on this, but not been able to find an exact answer. 我已经用谷歌搜索了一下,但是没有找到确切的答案。 We are seeing the following errors in our logs: 我们在日志中看到以下错误:

Timeout expired. 超时时间已到。 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. 这可能是因为所有池化连接都在使用中,并且达到了最大池大小。 Stack Trace: at MySql.Data.MySqlClient.MySqlPool.GetConnection() at MySql.Data.MySqlClient.MySqlConnection.Open() 堆栈跟踪:位于MySql.Data.MySqlClient.MySqlConnection.Open()处的MySql.Data.MySqlClient.MySqlPool.GetConnection()

I can monitor client connections on the MySQL server (and they appear fine), but the error is occurring in the ASP application. 我可以监视MySQL服务器上的客户端连接(它们看起来很好),但是在ASP应用程序中发生了错误。 There is nothing obvious in my code, so I wanted to monitor the connection pool and see what was going on. 我的代码中没有什么显而易见的,因此我想监视连接池并查看发生了什么。 I want to add MySQL performance counters into performance monitor in windows. 我想将MySQL性能计数器添加到Windows的性能监视器中。 But the only MySQL counters I see are HardProcedureQueries and SoftProcedureQueries. 但是我看到的仅有的MySQL计数器是HardProcedureQueries和SoftProcedureQueries。 SQL Server and Oracle have a load related to Connection pooling and other items of interest. SQL Server和Oracle具有与连接池和其他相关项有关的负载。 There have been some unanswered articles in different forums asking the same thing. 在不同的论坛上有一些未回答的文章问同样的事情。

So, how do people out there monitor ASP .NET MySQl connection pool counters in IIS on Windows? 那么,人们如何在Windows上的IIS中监视ASP .NET MySQl连接池计数器?

We're using .NET 4 on IIS 7.5 on Windows Server 2008 我们正在Windows Server 2008的IIS 7.5上使用.NET 4

I have done two things to help with this problem. 我已经做了两件事来解决这个问题。

The full code I use is: 我使用的完整代码是:

string path = u.MapPath("~/bin/MySql.Data.dll");
Assembly ms = Assembly.LoadFrom(path);
Type type = ms.GetType("MySql.Data.MySqlClient.MySqlPoolManager");
MethodInfo mi = type.GetMethod("GetPool", BindingFlags.Static | BindingFlags.Public);

var pool = mi.Invoke(null, new object[] { new MySqlConnectionStringBuilder(ConnectionString) });
Type mip = ms.GetType("MySql.Data.MySqlClient.MySqlPool");
MemberInfo[] mei1 = mip.GetMember("inUsePool", BindingFlags.NonPublic);
totalAvailable = (int)pool.GetType().InvokeMember("available", BindingFlags.GetField | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance, null, pool, new object[] { });
var o = pool.GetType().InvokeMember("inUsePool", BindingFlags.GetField | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, null, pool, new object[] { });
var o1 = pool.GetType().InvokeMember("idlePool", BindingFlags.GetField | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, null, pool, new object[] { });
inUseCount = (int)o.GetType().InvokeMember("Count", BindingFlags.GetProperty | BindingFlags.Instance | BindingFlags.Public, null, o, null);
idleCount = (int)o1.GetType().InvokeMember("Count", BindingFlags.GetProperty | BindingFlags.Instance | BindingFlags.Public, null, o1, null);

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

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