I would like to connect 100000 SignalR users to IIS (Windows Server 2016). Everything works fine until around 16000 connections. Then I start to receive this error:
Only one usage of each socket address (protocol/network address/port) is normally permitted
Here is my client code - it's a loop that creates all SignalR objects and it connects to the server:
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();
}
Connect function:
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;
}
I added to machine.config this under <system.web>:
<processModel autoConfig="false" maxIoThreads="999999" maxWorkerThreads="999999" memoryLimit="999999" minIoThreads="999999" minWorkerThreads="999999" />
I added to regedit:
MaxUserPort 65535 TcpTimedWaitDelay 30
I suppose that IIS has no more free sockets or ports. Maybe I'm wrong - can I tweak it somehow?