我使用 Microsoft.AspNetCore.SignalR.Client 对托管在 Windows Server 2016 标准上的 SignalR(ASP.NET Core)应用程序进行负载测试。
已安装 Dotnet 核心托管 2.1.1
而且我不能创建超过 3000 (2950-3050) 个连接。
已经尝试过这里描述的建议:
为
UseKestrel
添加了限制(如果我将值设置为 100 或 1000,这似乎有效):var host = new WebHostBuilder()
.UseKestrel(options =>
{
options.Limits.MaxConcurrentConnections = 50000;
options.Limits.MaxConcurrentUpgradedConnections = 50000;
})
通过添加以下内容更改了所有 aspnet.config 文件:
<system.web>
<applicationPool maxConcurrentRequestsPerCPU="50000" />
</system.web>
执行了这个命令:
cd %windir%\System32\inetsrv\appcmd.exe 设置配置/section:system.webserver/serverRuntime/appConcurrentRequestLimit:50000
为 添加了性能计数器Web 服务\当前连接 - 最大连接数 .并且最大连接数增加到 3300 并停止。
服务器日志中没有异常(exception)。但是我觉得系统有一些限制。
服务器 IIS 日志仅包含以下内容:
GET /messageshub id=A_3x1sH9kHM1Rc3oPSgP6w 80 - 172.20.192.11 - - 404 0 0 3
客户端异常基本上如下:
System.Net.Http.HttpRequestException: Error while copying content to a stream. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
最佳答案
在 Windows 上,您可能会遇到动态端口分配问题。
默认情况下,Windows 有 5000 个端口号准备分配给 TCP 连接,其中 1024 个保留给操作系统本身,您最终将有 3977 个端口可以自由分配。
在您的情况下,您提到的数字是 3300,但可能建立了 3300 个连接,其中 677 个是 Time_Waited。
无论如何,我建议使用
netstat -an | find 'Established" -c
netstat -an | find 'TIME" -c
netstat -an | find 'CLOSED" -c
为了找出在您收到 IO 异常时已建立的 & time_wait & close_wait 连接的数量,如果数量接近 5000,只需将其添加到您的注册表中,然后重新启动并再次测试
[HKEY_LOCAL_MACHINE \System \CurrentControlSet \Services \Tcpip \Parameters]
MaxUserPort = 5000 (Default = 5000, Max = 65534)
关于asp.net-core - ASP.NET Core SignalR websocket 连接限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51242689/