asp.net-core - ASP.NET Core SignalR websocket 连接限制
问题描述
我使用 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 Service\Current Connections - Maximum Connections添加了性能计数器。最大连接数增加到 3300 并停止。
服务器日志中没有异常。但是我觉得系统有一些限制。
服务器 IIS 日志仅包含以下内容:
获取 /messageshub id=A_3x1sH9kHM1Rc3oPSgP6w 80 - 172.20.192.11 - - 404 0 0 3
客户端异常基本上如下:
System.Net.Http.HttpRequestException:将内容复制到流时出错。---> System.IO.IOException: Unable to read data from the transport connection: 一个现有的连接被远程主机强行关闭。
解决方案
在 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)
推荐阅读
- amazon-web-services - 通过 aws-sdk javascript 或来自 aws-console 的 Amazon S3 存储桶存储量限制(以 GB 为单位)
- javascript - 如何在 Vue3 中启用仅使用 TypeScript 的道具键入
- c++ - 我的代码在 C++ 中计算两个矩形的重叠面积有什么问题?
- google-apps-script - 如何跳到特定单元格
- bash - 如何从 bash 中的“keytool”命令中删除警告
- windows - 我不小心将我的 git 编辑器设置为 Atom,如何将其恢复为 Git Bash?
- shell - 无法使用 ffmpeg 将评论元数据提供给 MP3 文件
- shared-libraries - 是否可以在 Pike 语言中使用外部 C 库?
- javascript - 如何将变量从一个组件传递到另一个组件?
- c# - .net 核心中的 Web 请求处理程序未找到?