简体   繁体   English

c# SignalR 初始连接性能chathub示例

[英]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.好的,我知道我们有很多关于 SignalR 的问题,我的问题是关于初始连接性能。

I am building an intranet based application, that will use SignalR to display update messages to a user, note I said A user.我正在构建一个基于 Intranet 的应用程序,它将使用 SignalR 向用户显示更新消息,注意我说的是用户。 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.在站点内,我有一个页面更新 sql 数据库表中的字段,然后由 windows 服务读取并开始将电子表格导入站点数据库。 As this import routine is executing, messages are sent using SignalR to a standard ASP.Net MVC 5 view.在执行此导入例程时,使用 SignalR 将消息发送到标准 ASP.Net MVC 5 视图。

The base example is from Example Code .基本示例来自Example Code

So I the ASP MVC implementation as per this example above and a C# Windows Service which is sending messages to it.所以我按照上面的这个例子实现了 ASP MVC 和一个 C# Windows 服务,它正在向它发送消息。

 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?如何减少这种启动延迟?

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.我上面的代码片段在 // do stuff 区域,一个存储的过程运行了很长时间,从而导致了这个问题。

So, check what the task is doing!所以,检查任务在做什么!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM