asp.net-mvc - SignalR 似乎减慢了我的 MVC/Azure 应用程序的启动速度

标签 asp.net-mvc performance azure signalr

我有一个 MVC 应用程序,它在 Windows Azure 上的 WebRole 上运行在 .NET 4.5 下,使用 SignalR 1.0 -alpha2,并使用 ServiceBus 背板。在我的 App_Start 文件夹中,我有 RegisterHubs.cs,如下所示:

[assembly: PreApplicationStartMethod(typeof(pageengine.studio.RegisterHubs), "Start")]

namespace pageengine.studio
{
    public static class RegisterHubs
    {
        public static void Start()
        {
            // Register the default hubs route: ~/signalr/hubs
            RouteTable.Routes.MapHubs();
        }
    }
}

在 Global.asax 中,我有以下内容:
protected void Application_Start()
{
    AreaRegistration.RegisterAllAreas();
    FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
    RouteConfig.RegisterRoutes(RouteTable.Routes);
    String connectionString = "Endpoint=sb://MYNAMESPACE.servicebus.windows.net/;SharedSecretIssuer=MY_ISSUER;SharedSecretValue=MY_SECRET_VALUE";
    GlobalHost.DependencyResolver.UseWindowsAzureServiceBus(connectionString, 1);
}

我已经运行了上述测试(称为 MVC + SignalR + ServiceBus),使用 GlobalHost.DependencyResolver ... Global.asax 中的行注释掉了(MVC + SignalR),并且两行都是 [assembly: PreApplicationStartMethod ...RouteTable.Routes.MapHubs();也注释掉了(MVC 单独)。

在开始之前,我使用 Start without Debugging(并部署到 IIS Express)来启动 Azure 模拟器,在每次评论/取消评论后,我重建应用程序,然后在 Google Chrome 中重新加载。我十次测试的平均加载时间如下:

MVC Alone: 1.33 seconds

MVC + SignalR: 31.95 seconds

MVC + SignalR + ServiceBus: 53.1 seconds



我没有在我的实时 Azure 站点上运行相同的比较,但运行这些测试的原因是在实现 SignalR 后,它的运行速度明显变慢。

我原以为这只是因为 SignalR 处于 alpha 阶段,但其他地方的讨论 ( signalR MVC site loads indefinitely after signalR install ) 表明这不应该如此。我不确定我上面的实现是否有问题,或者这是 Azure 特定的问题,还是其他问题。

有没有其他人遇到类似的性能问题?我上面的代码有什么问题吗?有没有人有任何潜在的补救措施?

更新

我在 RegisterHubs 的开头和结尾向 WebRole Start 和 Run 方法添加了一条跟踪语句。方法,以及 Application_Start 的开头和结尾方法,并注释掉了 ServiceBus 代码,所以我只是在测试 MVC + SignalR。

同样,经过多次测试,结果是一致的:

Web Role OnStart: 20:55:17

Web Role Run: 20:55:17

RegisterHubs Start In: 20:55:28

RegisterHubs Start Out: 20:56:10 // 42 seconds. Average was nearer 45.

Application_Start In: 20:56:14

Application_Start Out: 20:56:21



作为引用,我的 RegisterHubs 方法现在如下所示:
public static void Start()
{
    System.Diagnostics.Debug.WriteLine("RegisterHubs Start In: " + DateTime.Now.ToLongTimeString());
    // Register the default hubs route: ~/signalr/hubs
    RouteTable.Routes.MapHubs();
    System.Diagnostics.Debug.WriteLine("RegisterHubs Start Out: " + DateTime.Now.ToLongTimeString());
}

进一步更新

问题是(具有讽刺意味的)在 PerformaceCounterManager 中类,在 Microsoft.AspNet.SignalR.Core集会。

函数SetCounterProperties()电话LoadCounter在 23 个不同的循环中 _counterProperties .这些调用中的每一个都失败并处理异常,导致返回 _noOpCounter ,但是失败需要一到两秒的时间发生,并且累积到四十秒的延迟(所有这些时间在调试器打开的情况下 - 当然没有它会更快,但仍然明显滞后)。

这是已处理异常的跟踪,以防万一:
A first chance exception of type 'System.InvalidOperationException' occurred in System.dll InvalidOperation: SignalR - Errors: Hub Invocation Total - deployment18(966).Azure.Studio_IN_0_Web - System.InvalidOperationException: Cannot load Counter Name data because an invalid index '' was read from the registry. at System.Diagnostics.PerformanceCounterLib.GetStringTable(Boolean isHelp) at System.Diagnostics.PerformanceCounterLib.get_NameTable() at System.Diagnostics.PerformanceCounterLib.get_CategoryTable() at System.Diagnostics.PerformanceCounterLib.CategoryExists(String category) at System.Diagnostics.PerformanceCounterLib.CategoryExists(String machine, String category) at System.Diagnostics.PerformanceCounterCategory.Exists(String categoryName, String machineName) at System.Diagnostics.PerformanceCounterCategory.Exists(String categoryName) at Microsoft.AspNet.SignalR.Infrastructure.PerformanceCounterManager.LoadCounter(String categoryName, String counterName, String instanceName) in d:\Work\CLIENTS\PageEngine\Resources\SignalR-master\src\Microsoft.AspNet.SignalR.Core\Infrastructure\PerformanceCounterManager.cs:line 275
我能找到的最简单的解决方法是没有 PerformanceCounters。暂时我已经修改了GetPropertyInfo()简单返回 new PropertyInfo[0] .我修改了 LoadCounter永远返回 _noOpCounter .启动时间现在约为 5 秒,对于服务总线则为 10 秒。

最佳答案

这是 SignalR 1-alpha2 中的一个错误,现已在 github 上报告:https://github.com/SignalR/SignalR/issues/1063

更新

...现在已修复:https://github.com/SignalR/SignalR/commit/fda3aa41a9250a072e8487882ae806ffe547f2bb

关于asp.net-mvc - SignalR 似乎减慢了我的 MVC/Azure 应用程序的启动速度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13612970/

相关文章:

c# - 使用存储库出现错误没有为此对象定义无参数构造函数

c# - SetPrincipal (@User.Identity.Name) 来自 ASP.Net MVC 中的 cookie

c# - 此资源不支持“multipart/form-data”

PHP 常量 : Advantages/Disadvantages

javascript - 提高重复性 Mongo 数据库访问任务的性能

database - 是否可以将 sdf umbraco 数据库转换为 Azure SQL?

c# - 当我在 asp.net mvc Controller 操作中验证失败时,如何保留我的 url

azure - 如何限制Azure中安全组的删除?

azure - 在 C# 中检索 Azure 队列消息长度

android - 我想知道 android 中 Activity 和服务之间的线程流