-
Hi, Logic psuedo explained:
public int[] GetPoolStatsViaReflection()
{
var asm = typeof(MySqlConnectionStringBuilder).Assembly;
var poolManagerType = asm.GetType("MySql.Data.MySqlClient.MySqlPoolManager"); // internal sealed
var poolType = asm.GetType("MySql.Data.MySqlClient.MySqlPool"); // internal sealed
var pool = poolManagerType.InvokeMember("GetPool", System.Reflection.BindingFlags.InvokeMethod | System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public, null, null, new object[] { this.connectionStringBuilder });
const System.Reflection.BindingFlags nonPublicInstanceField = System.Reflection.BindingFlags.GetField | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance;
var totalAvailable = (int)poolType.InvokeMember("available", nonPublicInstanceField, null, pool, new object[] { });
// List<Driver>
var inUsePool = (System.Collections.ICollection)poolType.InvokeMember("inUsePool", nonPublicInstanceField, null, pool, new object[] { });
// Queue<Driver>
var idlePool = (System.Collections.ICollection)poolType.InvokeMember("idlePool", nonPublicInstanceField, null, pool, new object[] { });
return new[] {totalAvailable, inUsePool.Count, idlePool.Count};
} I guess this lives in |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Related: #491 |
Beta Was this translation helpful? Give feedback.
-
I'm sure it goes without saying but this is completely unsupported. Moreover, this is highly concurrent code, and some of these properties are not safe to read when there are concurrent writers. |
Beta Was this translation helpful? Give feedback.
MySqlConnector.Core.ConnectionPool.s_pools
will contain all known connection pools:MySqlConnector/src/MySqlConnector/Core/ConnectionPool.cs
Line 600 in 62ad22d
MySqlConnector.Core.ConnectionPool.m_sessions.Count
has the number of idle (pooled) sessions:MySqlConnector/src/MySqlConnector/Core/ConnectionPool.cs
Line 607 in 62ad22d
MySqlConnector.Core.ConnectionPool.m_leasedSessions.Count
has the number of active (in-use) sessions:MySqlConnector/src/MySqlConnector/Core/ConnectionPool.cs
Line 608 in 62ad22d