var s = "User ID=teinfra_neo_netreplayassword=123456;DataBase=teinfra_neo_netreplay;Server=10.100.41.196ort=3980;Min Pool Size=1;Max Pool Size=28;CharSet=utf8;";
using (var conn = new MySqlConnection(s))
{
var comm = conn.CreateCommand();
comm.CommandText = "select count(*) from usertest;";
conn.Open();
var ret = comm.ExecuteScalar();
comm.CommandText = "select count(*) from information_schema.PROCESSLIST WHERE HOST like '10.22.12.245%';";
var len = comm.ExecuteScalar();
return $"查询结果:{ret} ,顺便查一下当前连接池的连接对象个数: {len}";
};
}
[Route("clearpool")]
public string Switch()
{
var s = "User ID=teinfra_neo_netreplayassword=123456;DataBase=teinfra_neo_netreplay;Server=10.100.41.196ort=3980;Min Pool Size=1;Max Pool Size=28;CharSet=utf8;";
using (var conn = new MySqlConnection(s))
{
conn.Open();
MySqlConnection.ClearPool(conn);
};
using (var conn = new MySqlConnection(s))
{
conn.Open();
var comm = conn.CreateCommand();
comm.CommandText = "select count(*) from information_schema.PROCESSLIST WHERE HOST like '10.22.12.245%';";
var len = comm.ExecuteScalar();
return $"之前已经清空连接池, 此次查询连接池有 {v1} 个连接对象";
}
}
}
1. 经过压测工具
[attach]145814[/attach]
2. mysql数据库对比 [attach]145815[/attach]
mysql的连接数查询命令, (host是web服务器IP):
select * from information_schema.PROCESSLIST WHERE HOST like '10.22.12.245%';