Search code examples
c#signalrsignalr-2

c# SignalR initial connection performance chathub example


OK, I know we have a lot of questions about SignalR, mine is about the initial connection performance.

I am building an intranet based application, that will use SignalR to display update messages to a user, note I said A user. Within the site, I have a page that updates a field in a sql database table, which is then read by a windows service and starts to import spreadsheets into the site database. As this import routine is executing, messages are sent using SignalR to a standard ASP.Net MVC 5 view.

The base example is from Example Code.

So I the ASP MVC implementation as per this example above and a C# Windows Service which is sending messages to it.

 connection = new HubConnection("http://localhost:64405/");
        connection.Credentials = new NetworkCredential(_config.ServiceAccount, _config.ServiceAccountPassword);
        myHub = connection.CreateHubProxy("chatHub");
        connection.Start().ContinueWith(task =>
        {
             // do stuff
        }

Now, As you guessed, this is currently all working locally on my machine and it does all work, but the connection to the hub is in minutes. After that, performance is fine, messages sent instantly.

How can this startup delay be reduced?


Solution

  • OK, after looking at this, I finally found the issue.

    ME!

    I the above code snippet in the // do stuff area, a stored proc ran that was taking a long time, thus causing the issue.

    So, check what the task is doing!