是否有可能将100000个SignalR用户连接到单个IIS?



我想将100000个SignalR用户连接到IIS (Windows Server 2016)。一切都很好,直到大约16000个连接。然后我开始收到这个错误:

每个套接字地址(协议/网络地址/端口)通常只允许使用一次

这是我的客户端代码-它是一个循环,创建所有SignalR对象,并连接到服务器:

private static void Run()
{            
for (int i = 0; i < 100000 ; i++)
{
Guid g = Guid.Empty;
string lG = g.ToString();
string lGS = lG.Substring(0, lG.Length - i.ToString().Length);
string lTenantIdentfier = lGS + i.ToString();

bool lConnected = false;
SignalRClient sc = new SignalRClient(lTenantIdentfier);
while (!lConnected)
{
sc.Stop();
lConnected = sc.Connect();
if (lConnected)
break;
Console.WriteLine("[" + lTenantIdentfier + "] - Repeating connection...");
System.Threading.Thread.Sleep(5000);
}
if ((i % 1000) == 0)
Thread.Sleep(5000);              
}
Console.ReadKey();            
}

连接功能:

public bool Connect()
{
try
{
if (connection != null)
{
Stop();
}
if (connection == null)
{
connection = new HubConnection("my_url");                 

connection.Headers.Add("TenantIdentifier", TenantIdentifier);
HubProxy = connection.CreateHubProxy("notificationHub");

GetNotification = HubProxy.On("NotifyChange", () =>
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("[" + TenantIdentifier + "] " + DateTime.Now);
});
}
connection.Start().Wait();
if (connection.State == ConnectionState.Connected)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("[" + TenantIdentifier + "] - Connected");            
connection.Closed -= Connection_Closed;
connection.Closed += Connection_Closed;
return true;
}
}
catch (Exception ex)
{
//Show exception
}
return false;
}

我添加到机器。在:

下配置
<processModel autoConfig="false" maxIoThreads="999999" maxWorkerThreads="999999" memoryLimit="999999" minIoThreads="999999" minWorkerThreads="999999" />

我添加到regedit:

MaxUserPort 65535TcpTimedWaitDelay 30

我想IIS没有更多的空闲套接字或端口。也许我错了,我能调整一下吗?

如注释中所述,原因似乎是客户端耗尽了空闲端口。MaxUserPort在windows上的默认值为5000,因此只有1024到4999之间的端口可用于客户端连接到服务器。服务器本身不能用完这种方式的空闲端口,因为所有的连接到相同的端口(以通常的web服务器为例,所有的客户端连接到端口80或端口443等,同样的故事在这里)。

然后尝试在一个循环中从客户端连接,为每个连接使用新的本地端口。我怀疑您可以连接超过(4999-1024)次,因为您没有显式地关闭signalR连接,但是您也没有将它们存储在某种全局列表中,因此它们符合垃圾收集的条件,垃圾收集将调用终结器,从而关闭连接。或者连接通过其他方式关闭,但速度不够快,因此在某些时候您耗尽了客户端的本地端口,但您拥有的数量可能不代表并发的连接数

客户端上设置MaxUserPort为65535和TcpTimedWaitDelay 30应该允许您从该客户端建立更多连接。

Evk是正确的,但我记得在查看用户连接量时读到了一些有趣的东西。

从最初的SignalR领导人,达米安·爱德华兹,早在2014年…是的,这是可能的。这应该是在ASP下。. NET版本2.x。但是如果你看了一些回复,Damien说。net CORE版本应该走得更高。

https://twitter.com/DamianEdwards/status/486642486350061568

新的@SignalR并发连接记录在10GB svr上:150,000连接(WebSockets), w/实验性缓冲池更改。

相关内容

最新更新