首页 新闻 搜索 专区 学院

简单接口压测报错 Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool

0
悬赏园豆:20 [待解决问题]

环境:net core 3.1
Microsoft.Data.SqlClient和System.Data.SqlClient都报这个错误

接口如下

        public async Task GetOrgan2List()
        {
            using (var con = new SqlConnection(GlobalConfig.ConnectionString))
            {
                con.Open();
                await Task.Delay(300);
                con.Close();
                con.Dispose();
            }
        }

压测10秒,999并发
ab -t 10 -c 999

报错

System.InvalidOperationException: 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.
   at Microsoft.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
   at Microsoft.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   at Microsoft.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
   at Microsoft.Data.SqlClient.SqlConnection.Open()
   at SP.Api.Areas.Exam.v1.Controllers.OrganController.GetOrgan2List()
溪爸的主页 溪爸 | 初学一级 | 园豆:134
提问于:2020-05-22 10:42
< >
分享
所有回答(2)
0

连接池爆了吧,打开太多tcp连接了。你压这个的目的是啥?

blackheart | 园豆:3290 (老鸟四级) | 2020-05-22 13:28
0

using (var con = new SqlConnection(GlobalConfig.ConnectionString))
{
con.Open();
await Task.Delay(300);
}

这样就可以, 连接池 需要通过字符串 配置(Max Pool Size 是连接池最大连接数,Min Pool Size 最少连接数)
Server=(local); Integrated Security=SSPI; Database=Northwind; Max Pool Size=512; Min Pool Size=5

Tom.汤 | 园豆:1977 (小虾三级) | 2020-05-22 14:01
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册