如何在IIS中监视.NET MySQL数据连接器的连接池 [英] How to monitor connection pooling for .NET MySQL Data Connector in IIS

查看:228
本文介绍了如何在IIS中监视.NET MySQL数据连接器的连接池的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在Google上对此进行了一些搜索,但是无法找到确切的答案.我们在日志中看到以下错误:

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:

超时已过期.超时时间过后才获得 池中的连接.这可能是因为所有共享 连接正在使用中,并且已达到最大池大小.堆栈跟踪:在 MySql.Data.MySqlClient.MySqlPool.GetConnection()在 MySql.Data.MySqlClient.MySqlConnection.Open()

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服务器上的客户端连接(它们看起来不错),但是在ASP应用程序中发生了错误.我的代码中没有什么显而易见的,因此我想监视连接池并查看发生了什么. 我想将MySQL性能计数器添加到Windows的性能监视器中.但是我看到的唯一的MySQL计数器是HardProcedureQueries和SoftProcedureQueries. SQL Server和Oracle具有与连接池和其他相关项有关的负载. 在不同的论坛上有一些悬而未决的文章问同样的事情.

I can monitor client connections on the MySQL server (and they appear fine), but the error is occurring in the ASP application. 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. But the only MySQL counters I see are HardProcedureQueries and SoftProcedureQueries. SQL Server and Oracle have a load related to Connection pooling and other items of interest. There have been some unanswered articles in different forums asking the same thing.

那么,人们如何在Windows上的IIS中监视ASP .NET MySQl连接池计数器?

So, how do people out there monitor ASP .NET MySQl connection pool counters in IIS on Windows?

我们在Windows Server 2008的IIS 7.5上使用.NET 4

We're using .NET 4 on IIS 7.5 on Windows Server 2008

推荐答案

我已经做了两件事来解决这个问题.

I have done two things to help with this problem.

  • Upgraded the MySQL drivers.
  • Used code from How to query the current size of the MySQL's .Net connector's connection pool? to create a web page to monitor the state of the connection pool on my server.

我使用的完整代码是:

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);

这篇关于如何在IIS中监视.NET MySQL数据连接器的连接池的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆