2014-04-09 24 views
1

我们有一个“小型的”NServiceBus应用程序,它使用十几个EF映射表和RabbitMQ作为通信媒介。使用NServiceBus.Host.Exe启动应用程序需要大约26s(调试版本和发行版本,无论是否附带调试器)。NServiceBus.Host,NGen和LoadFrom

添加EndpointConfigurationType应用程序设置后,加载时间下降2秒。

所以我一直在研究这个问题,在第一个查询中花费了大约8-10s的EF,并且它是各种生成例程。 NGen也可以提高EF加载性能:图书馆。

然而后NGEN:荷兰国际集团了库和起始NServiceBus.Host.exe,本地图像通过默认应用程序域加载,但是也通过一个额外的应用程序域(使用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,所以此基础上,融合应该已经加载了本机DLL为好。

EDIT2:这是“最小”的摄制不具有所有B &W¯¯nservicebus.host.exe的,但似乎在调试情况下工作。它开始于下2S与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, 
     }; 
    } 
} 
} 

回答

1

的26S我认为只是去与自我托管https://github.com/SimonCropp/NServiceBus.SelfHost#self-host

看到示例代码下面

的“服务功能”自主机国安局主机可以通过调用来取代以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(); 
     } 
    } 
} 
+0

TopShelf(什么NSB.Host使用的服务支持)他们自我不推荐使用他们的域名支持,所以我会实现一个可以加载我们的dll的简单帮助程序。我甚至不知道我们是否应该/不要将它们保存为dll。 –

相关问题