How to monitor connection pooling for .NET MySQL Data Connector in IIS(如何在 IIS 中监视 .NET MySQL 数据连接器的连接池)
问题描述
我对此进行了相当多的搜索,但无法找到确切的答案.我们在日志中看到以下错误:
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.
- 升级了 MySQL 驱动程序.
- 使用的代码来自 如何查询MySQL的.Net连接器的连接池的当前大小?创建一个网页来监控我服务器上连接池的状态.
- 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 数据连接器的连接池的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 IIS 中监视 .NET MySQL 数据连接器的连接池
基础教程推荐
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- 将 XML 转换为通用列表 2022-01-01