With a small number of users (<20), there aren't any problems. My server can push updates to the page when necessary and the users can interact with the page without slowdowns. When I make the page available to lots of users (>200), the page stops working or load times become unbearable. I think SignalR memory usage and connections are too high for the server to handle because new connections are made every time there's a postback and SignalR garbage collection is too slow to clean up the outdated connections.
Server Side:
public class MyHub : Hub
{
public void joinGroup(string groupName)
{
this.Groups.Add(this.Context.ConnectionId, groupName);
}
public void removeFromGroup(string groupName)
{
this.Groups.Remove(this.Context.ConnectionId, groupName);
}
public void broadcastUpdateToGroup(string groupName, string command, string message)
{
Clients.Group(groupName).updateTest(command + "~" + message);
}
}
I would use this code to send out a message:
var hubConnection = new HubConnection(liveHubURL);
var liveHub = hubConnection.CreateHubProxy("liveHub");
hubConnection.Start().Wait();
liveHub.Invoke("broadcastUpdateToGroup", "my group", "Alert", "Hello");
Task.Run(() => hubConnection.Dispose());
What I have tried:
I tried the SignalR Wiki Performance changes but still have the issue. FYI, I was having an issue with the small number of users at first but I increased the number of CPUs from 4 to 16 and that made everything run smoothly. I don't think increasing CPUs to something higher is the way I want to keep fixing this because it won't be scaleable for much higher number of users.