我们有一个“小”的NServiceBus应用程序,它使用十几个EF映射表和RabbitMQ作为通信介质。随着NServiceBus.Host.Exe的启动,应用程序的启动需要26s(调试和发布版本都包括在内,附带或不附加调试器)。
添加EndpointConfigurationType应用程序后,加载时间下降了2s。
所以我一直在研究这个问题,在第一个查询中使用了大约8-10的EF,这是各种不同的生成例程。通过NGen:ing库还可以提高EF的加载性能。
但是,在NGen:启动库并启动NServiceBus.Host.exe之后,默认的appdomain加载了本机映像,还加载了一个额外的appdomain (它使用IL ),因此看起来它使用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我所有的All都在NServiceBus.Host.exe的同一个目录中,因此在此基础上,融合也应该加载本机All。
edit2: --这是“最小”的repro,它没有nservicebus.host.exe的所有b&w,但是它似乎在调试情况下工作。它开始于低于2s与26s的Nservicebus.host.exe。
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,
};
}
}
}发布于 2014-04-12 01:37:09
我认为应该使用自我托管的https://github.com/SimonCropp/NServiceBus.SelfHost#self-host
参见下面的self主机示例代码
NSB主机的“服务特性”可以由对sc.exe https://github.com/SimonCropp/NServiceBus.SelfHost#install--uninstall的调用来替代。
class ProgramService : ServiceBase
{
IStartableBus bus;
static void Main()
{
using (var service = new ProgramService())
{
// so we can run interactive from Visual Studio or as a service
if (Environment.UserInteractive)
{
service.OnStart(null);
Console.WriteLine("\r\nPress any key to stop program\r\n");
Console.Read();
service.OnStop();
}
else
{
Run(service);
}
}
}
protected override void OnStart(string[] args)
{
Configure.GetEndpointNameAction = () => "SelfHostSample";
bus = Configure.With()
.DefaultBuilder()
.UnicastBus()
.CreateBus();
bus.Start(Startup);
}
static void Startup()
{
//Only create queues when a user is debugging
if (Environment.UserInteractive && Debugger.IsAttached)
{
Configure.Instance.ForInstallationOn<Windows>().Install();
}
}
protected override void OnStop()
{
if (bus != null)
{
bus.Shutdown();
}
}
}https://stackoverflow.com/questions/22969955
复制相似问题