Click here to Skip to main content
15,889,909 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
C#
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:
C#
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.
Posted
Updated 16-May-17 14:51pm
v4
Comments
Dave Kreskowiak 16-May-17 19:25pm    
This would seem like a code problem on the server side. Since we know nothing about your server side code, it's pretty much impossible for anyone to tell you what that would be.
Member 13204693 16-May-17 19:46pm    
I updated the question to include the very simple server side code. There is a routine that creates messages that it sends via broadcastUpdateToGroup(groupName, command, message) from time to time. Any help would be appreciated.
Dave Kreskowiak 16-May-17 20:52pm    
This isn't enough. You said you use that code to "send out a message". So, you're creating a new Hub every time you send a message? How many messages per second are you sending out?
Member 13204693 17-May-17 2:11am    
Wow! Dave THANK YOU. I moved the first three hubConnection lines to the initializing portion of my class and removed the hubConnection disposing line. So the only code for sending out messages now is the liveHub.Invoke line and everything seems smoother. I didn't realize until your last reply that I didn't need to create and destroy the hub each time I sent out a message. I'll try it out with a larger number of users and see how it does but it looks like you led me to a solution. Thanks again.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900