Slow SignalR HubConnection Start

user2029101

My Question: Is there a way to speed up the initial connect to the hub?

Details:

I am using SignalR at a selfhosted Webservice @Win 8.1. The Hub application got local clients and remote clients.

I granded SignalR access via DNS, localhost and 127.0.0.1 by:

'netsh http add urlacl url=http://<Replace>:<Port>/ user=Everyone'

Usually all clients even the local ones are using DNS. And it works.

My problem is one sporned child process (using c# Microsoft.AspNet.SignalR.Client.HubConnection). It usually connects withing 400ms. Thats ok. But sometimes it takes seconds.

I have tried to switch at this client to 127.0.0.1 and localhost but without any change.

Afterwards the initial connect, SignalR is pritty fast.

If there is no easy way I have to switch back to plain UDP.

SignalR Config at Hub:

using System;
using System.Web.Http;
using Microsoft.Owin;
using Microsoft.Owin.Cors;
using Microsoft.Owin.FileSystems;
using Microsoft.Owin.StaticFiles;
using Owin;

[assembly: OwinStartup(typeof(SignalRStartUp))]
namespace Onsite
{
    public class SignalRStartUp
    {
        // Any connection or hub wire up and configuration should go here
        public void Configuration(IAppBuilder pApp)
        {
            try
            {
                pApp.UseCors(CorsOptions.AllowAll);
                pApp.MapSignalR();
                pApp.UseFileServer(true);

                var lOptions = new StaticFileOptions
                {
                    ContentTypeProvider = new CustomContentTypeProvider(),
                    FileSystem = new PhysicalFileSystem(Constants.Root)
                };

                pApp.UseStaticFiles(lOptions);

                // Configure Web API for self-host. 
                var lConfig = new HttpConfiguration();
                lConfig.Routes.MapHttpRoute("RemoteApi", "api/{controller}/{action}");
                lConfig.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}", new { id = RouteParameter.Optional });
                pApp.UseWebApi(lConfig); 
            }
            catch (Exception lEx)
            {
                Logger.Error(lEx);
            }
        }
    }
}

Startup at the Client:

public static string GetConnectionString(string pHost = null)
{
    var lHost = pHost ?? GetMainClientDns();
    return string.Format("http://{0}{1}", lHost, SignalRPort);
}

private void StartSignalR()
{
    try
    {
        var lConnectionString = GetConnectionString("127.0.0.1");

        var lStopWatch = new Stopwatch();
        lStopWatch.Restart();
        IsConnectingHost = true;

        _connection = new HubConnection(lConnectionString, string.Format("AccessKey={0}&Role={0}", Constants.AccessKeyPlugIn));
        _connection.Reconnected += SetConnected;
        _connection.Reconnecting += SetDisConnected;

        MTalkHub = _connection.CreateHubProxy("OnsiteHub");

        MTalkHub.On("RequestSetNext", RequestSetNext);
        MTalkHub.On("RequestSetPrevious", RequestSetPrevious);
        MTalkHub.On("RequestEcho", RequestEcho);

        _connection.TransportConnectTimeout = _transportConnectTimeout;

        var lTask = _connection.Start();
        lTask.Wait();

        lStopWatch.Stop();

        SetConnected();
     }
    catch (TargetInvocationException lEx)
    {
        IsDisconnected = true;
        Task.Run(() => TryToConnect());
        Logger.Fatal(string.Format("Server failed to start. Already running on: '{0}'", lConnectionString), lEx);
    }
    catch (Exception lEx)
    {
        IsDisconnected = true;
        Task.Run(() => TryToConnect());
        Logger.Fatal(string.Format("Connecting to: '{0}' failed!", lConnectionString.ToStringNs()));
    }
    finally
    {
        IsConnectingHost = false;
    }
}
user2029101

After a bugfix for another issue I the long initial connect was also gone.

What I have found: There was a race condition and rarely a lock with FileAccess via network share blocked the Hub by updating the local cached thumbnails.

Thx anyway!

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

SignalR dispose of HubConnection

From Dev

SignalR Client HubConnection.Start() throws exception and doesn't keep trying to connect like the documentation says it should

From Dev

android signalR hubconnection application negotiation failed with server

From Dev

SignalR Java Client - NegotiationException when starting HubConnection

From Dev

android signalR hubconnection application negotiation failed with server

From Dev

Slow Startup for setup SignalR connection

From Dev

Teamcity start very slow

From Dev

Slow start of Midnight Commander

From Dev

Start activity is slow

From Dev

SignalR service crashing on start up

From Dev

SignalR slow initiating connection (and retrieving data)

From Dev

SignalR works slow in UWP and fast in console application

From Dev

$.hubConnection is undefined

From Dev

Nancy slow to start accepting requests

From Dev

Slow logback start up times

From Dev

IIS First Start is too slow

From Dev

SignalR Broadcast Messages Duplicated after Stop/Start

From Dev

SignalR negotiate succesfully but fail at start request

From Dev

How to call SignalR hub when application start?

From Dev

SignalR - very slow to invoke hub from WPF app

From Dev

Android app starts slow, but works fine after that slow start

From Dev

Is TCP Slow Start algorithm a reason for slow transfers of many single files?

From Dev

Is TCP Slow Start algorithm a reason for slow transfers of many single files?

From Dev

Python is very slow to start on Windows 7

From Dev

Websphere MQ receive channel start up slow

From Dev

NGINX download slow to start with send_file

From Dev

Visual studio Ultimate 2013 slow start on debug

From Dev

java - regex slow performance without "^" as start of pattern

From Dev

Start Menu search is very slow in Windows 8.1

Related Related

  1. 1

    SignalR dispose of HubConnection

  2. 2

    SignalR Client HubConnection.Start() throws exception and doesn't keep trying to connect like the documentation says it should

  3. 3

    android signalR hubconnection application negotiation failed with server

  4. 4

    SignalR Java Client - NegotiationException when starting HubConnection

  5. 5

    android signalR hubconnection application negotiation failed with server

  6. 6

    Slow Startup for setup SignalR connection

  7. 7

    Teamcity start very slow

  8. 8

    Slow start of Midnight Commander

  9. 9

    Start activity is slow

  10. 10

    SignalR service crashing on start up

  11. 11

    SignalR slow initiating connection (and retrieving data)

  12. 12

    SignalR works slow in UWP and fast in console application

  13. 13

    $.hubConnection is undefined

  14. 14

    Nancy slow to start accepting requests

  15. 15

    Slow logback start up times

  16. 16

    IIS First Start is too slow

  17. 17

    SignalR Broadcast Messages Duplicated after Stop/Start

  18. 18

    SignalR negotiate succesfully but fail at start request

  19. 19

    How to call SignalR hub when application start?

  20. 20

    SignalR - very slow to invoke hub from WPF app

  21. 21

    Android app starts slow, but works fine after that slow start

  22. 22

    Is TCP Slow Start algorithm a reason for slow transfers of many single files?

  23. 23

    Is TCP Slow Start algorithm a reason for slow transfers of many single files?

  24. 24

    Python is very slow to start on Windows 7

  25. 25

    Websphere MQ receive channel start up slow

  26. 26

    NGINX download slow to start with send_file

  27. 27

    Visual studio Ultimate 2013 slow start on debug

  28. 28

    java - regex slow performance without "^" as start of pattern

  29. 29

    Start Menu search is very slow in Windows 8.1

HotTag

Archive