我们有一个“小型” NServiceBus 应用程序,它使用十几个 EF 映射表和 RabbitMQ 作为通信媒介。使用 NServiceBus.Host.Exe 启动应用程序需要大约 26 秒(调试和发布版本,带有或不带有调试器)。
添加 EndpointConfigurationType 应用程序设置后,加载时间下降了 2s。
所以我一直在研究这个,大约 8-10 秒在第一个查询中与 EF 一起使用,它是各种生成例程。NGen:ing 库也可以增强 EF 加载性能。
然而,在 NGen:ing 库并启动 NServiceBus.Host.exe 之后,默认情况下会加载原生图像,但也会通过额外的 appdomain(使用 IL dll)加载,因此看起来它使用LoadFrom加载依赖项。
有没有解决的办法?我们想将 NSB.Host.exe 用于它的 Windows 服务功能(我们对重新实现不感兴趣)。其他“IWantTo...”功能也很好,因为我们已经有几个(16 个?)端点使用这些功能。
编辑: http: //blogs.msdn.com/b/abhinaba/archive/2014/02/18/net-ngen-explicit-loads-and-load-context-promotion.aspx 我所有的 dll 都在与 NServiceBus 相同的目录中.Host.exe,因此基于此,Fusion 也应该加载本机 dll。
edit2:这是“最小”的再现,没有 nservicebus.host.exe 的所有黑白,但它似乎在调试情况下工作。它在 Nservicebus.host.exe 的 2 秒和 26 秒内启动
using NServiceBus;
using BABAR.Configuration;
using System;
using System.Collections.Generic;
using System.Reflection;
namespace BABAR.NGENHelper
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Starting: {0}", DateTime.Now.ToLongTimeString());
StartNSB();
Console.WriteLine("NSB started: {0}", DateTime.Now.ToLongTimeString());
}
private static void StartNSB()
{
// this ends up loading EF, in this case unnoticeable
NServiceBus.Unicast.Transport.TransportConnectionString.Override(
GetRabbitMQConnectionString);
NServiceBus.SetLoggingLibrary.Log4Net(() => log4net.Config.XmlConfigurator.Configure());
var semibus = Configure.With(GetNSBAssemblies())
.DefaultBuilder()
.DefineEndpointName("NGENHelper")
.UseTransport<NServiceBus.RabbitMQ>()
.PurgeOnStartup(false)
.UnicastBus()
.ImpersonateSender(false)
.RunHandlersUnderIncomingPrincipal(false)
.CustomConfigurationSource(new DefaultNServiceBusConfigurationSource())
.MessageForwardingInCaseOfFault()
.DisableTimeoutManager();
var bus = semibus.CreateBus()
.Start(() => Configure.Instance.ForInstallationOn<NServiceBus.Installation.Environments.Windows>()
.Install());
}
public static string GetRabbitMQConnectionString()
{
var nc = new Access().GetNode<NodeConfiguration>();
return nc.RabbitConnectionString;
}
internal static IEnumerable<Assembly> GetNSBAssemblies()
{
return new[] {
typeof(NServiceBus.RabbitMQ).Assembly, // IConfigureTransport for NSB
typeof(BABAR.Bootstrapper).Assembly,
};
}
}
}