【发布时间】:2018-02-19 12:21:23
【问题描述】:
我正在对 web api (webapi2) 进行压力测试,在 0 秒内有 20 个用户登录。我收到以下错误。
System.Data.Entity.Core.EntityCommandExecutionException: An error occurred while executing the command definition. See the inner exception for details. ---> System.InvalidOperationException: Invalid operation. The connection is closed.
另一个错误
System.Data.Entity.Core.EntityException: The underlying provider failed on Open. ---> System.InvalidOperationException: The connection was not closed. The connection's current state is connecting.
每次创建新的 DBContext 时,我获取 DBContext 的代码:
public static ForcesChecker_Context GetDataContext()
{
return new ForcesChecker_Context();
}
对于一个 web api 请求,此代码将被执行多次,并创建此对象的多个实例。当我一次调用 20 个用户时,它会生成 20* ~10 = ~200 个对象。
我的连接字符串:
Min Pool Size=1;Max Pool Size=200;
似乎存在竞争条件。
哪些设置有助于允许更多用户同时访问我的系统?
【问题讨论】:
标签: entity-framework-6 race-condition stress-testing