ASP.NET Core SignalR websocket connection limit

*爱你&永不变心* 提交于 2021-01-27 13:52:44

问题


I produce load testing of SignalR (ASP.NET Core) application hosted at Windows Server 2016 standard using Microsoft.AspNetCore.SignalR.Client. Dotnet core hosting 2.1.1 installed

And i can not create more than 3000 (2950-3050) connections.

Already tried recomendations as described here:

  • How to configure concurrency in .NET Core Web API?
  • Limiting performance factors of WebSocket in ASP.NET 4.5?
  • Set limit concurrent connections for websocket on iis 8

Added limits to UseKestrel (this seems to work if i set values to 100 or 1000):

var host = new WebHostBuilder()
    .UseKestrel(options =>
    {
        options.Limits.MaxConcurrentConnections = 50000;
        options.Limits.MaxConcurrentUpgradedConnections = 50000;
    })

Changed all aspnet.config files by adding this:

<system.web>
    <applicationPool maxConcurrentRequestsPerCPU="50000" />
</system.web>

Executed this command:

cd %windir%\System32\inetsrv\ appcmd.exe set config /section:system.webserver/serverRuntime /appConcurrentRequestLimit:50000

Added performance counter for Web Service\Current Connections - Maximum Connections. And Maximum Connections increases to 3300 and stops.

There are no exceptions in server logs. But I feel that there are some restrictions in system.

Server IIS logs contains only this:

GET /messageshub id=A_3x1sH9kHM1Rc3oPSgP6w 80 - 172.20.192.11 - - 404 0 0 3

Client exceptions is basically the following:

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.


回答1:


On Windows you may have dynamic port assignment issue . Windows by default has 5000 port numbers ready to be assigned to TCP connections and 1024 of them are reserved for the OS itself which you will end up with 3977 ports free to be assigned . In your case the number is 3300 as you mentioned but it's possible that 3300 of the connections are established and 677 of them are Time_Waited. In any case i recommend to use

netstat -an | find 'Established" -c 
netstat -an | find 'TIME" -c 
netstat -an | find 'CLOSED" -c 

In order to figure out the number of established & time_wait & close_wait connections at the time you received the IO exception and if the number is close to 5000 just add this to your registry and reboot and test again

  [HKEY_LOCAL_MACHINE \System \CurrentControlSet \Services \Tcpip \Parameters]
MaxUserPort = 5000 (Default = 5000, Max = 65534)


来源:https://stackoverflow.com/questions/51242689/asp-net-core-signalr-websocket-connection-limit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!