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

How to monitor connection pooling for .NET MySQL Data Connector in IIS(如何在 IIS 中监视 .NET MySQL 数据连接器的连接池)
本文介绍了如何在 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 数据连接器的连接池的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
how do i pass parameters to aspnet reportviewer(如何将参数传递给aspnet report查看器)
Bind multiple parameters from route and body to a model in ASP.NET Core(在ASP.NET Core中将路由和主体中的多个参数绑定到一个模型)
Custom model binding in AspNet Core WebApi?(AspNet Core WebApi中的自定义模型绑定?)
How to minify in .net core mvc view?(如何在.Net核心MVC视图中缩小?)