EFCore 使用DbContextPool提高EfCore查询性能
原文: EFCore 使用DbContextPool提高EfCore查询性能 EFCore2.0 为DbContext引入新的注册方式:透明地注册了 DbContext实例池 services.AddDbContextPool<UserModelContext>(options => options.UseSqlServer(Configuration.GetConnectionString("sqlstring"))); 一如既往支持lambda方式注册连接字符串 - 默认的连接池数量为 128 - 每次使用完DbContext不会释放对象,而是重置并回收到DBContextPool Web程序中通过重用池中DbContext实例可提高高并发场景下的吞吐量, 这在概念上类似于ADO.NET Provider原生的连接池操作方式,具有节省DbContext实例化成本的优点, 这也是EFCore2.0 其中一个性能亮点。 验证SQL Server会话中的有效连接数SQL: SELECT DEC.session_id, DEC.protocol_type, DEC.auth_scheme, DES.login_name, DES.login_time FROM sys.dm_exec_sessions AS DES JOIN sys.dm_exec_connections AS DEC