流畅nHibernate慢启动时间 [英] Fluent nHibernate Slow Startup Time

查看:465
本文介绍了流畅nHibernate慢启动时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用流利的NHibernate,我喜欢它!
我有一个小问题:启动时间约10秒,我不知道如何优化Fluent nHibernate
为了使这个启动时间更少的问题,我把它放在一个线程。 p>

有人能解决这个问题吗?并回复下面的代码修改以提高性能?



我看到这样的:
http://nhforge.org/blogs/nhibernate/archive/2009/03/13/an-improvement -on-sessionfactory-initialization.aspx
,但我不知道如何使这项工作与流利的nHibernate。



我的代码是像这样:

  public static ISession ObterSessao()
{
System.Threading.Thread.CurrentThread。 Priority = System.Threading.ThreadPriority.Highest;

string ConnectionString = ConfigurationHelper.LeConfiguracaoWeb(EstoqueDBNet); //我的连接字符串到这里

var config = Fluently.Configure()
.Database(FluentNHibernate.Cfg.Db.MySQLConfiguration.Standard.ConnectionString(ConnectionString));

config.Mappings(m => m.FluentMappings.AddFromAssembly(Assembly.GetExecutingAssembly()));

var session = config
.BuildSessionFactory()
.OpenSession();

System.Threading.Thread.CurrentThread.Priority = System.Threading.ThreadPriority.Normal;

return session; Phill有正确的答案,你可以用这个方法来解决这个问题。你可以用这个解决方案来解决这个问题。但进一步了解一下 http://nhibernate.info/blog/2009/03/13/an-improvement-on-sessionfactory-initialization.html 将NHibernate配置序列化为一个文件,因此您不必每次都重建它您启动应用程序的时间。这可能或可能不会有点快,取决于各种因素(主要是你有的映射的数量) - 根据这个,

p>

$ p





















然后,使用 Fluently.Configure(Configuration cfg) overload在创建FluentConfiguration时注入配置(而不是让它自动为你构建)。


I am using Fluent NHibernate and I like it ! I am having a little issue: The startup time is about 10 seconds and I don´t know how to optimize Fluent nHibernate To make this startup time less problematic, I put it on a Thread.

Could somebody tell a solution to this? And reply with the code below modified to make the performance improvement?

I saw something like this on: http://nhforge.org/blogs/nhibernate/archive/2009/03/13/an-improvement-on-sessionfactory-initialization.aspx but I don´t know how to make this work together with Fluent nHibernate.

My code is like this:

public static ISession ObterSessao()        
{
        System.Threading.Thread.CurrentThread.Priority = System.Threading.ThreadPriority.Highest;

        string ConnectionString = ConfigurationHelper.LeConfiguracaoWeb("EstoqueDBNet"); // My Connection string goes here

        var config = Fluently.Configure()
            .Database(FluentNHibernate.Cfg.Db.MySQLConfiguration.Standard.ConnectionString(ConnectionString));

        config.Mappings(m => m.FluentMappings.AddFromAssembly(Assembly.GetExecutingAssembly()));

        var session = config
            .BuildSessionFactory()
            .OpenSession();

        System.Threading.Thread.CurrentThread.Priority = System.Threading.ThreadPriority.Normal;

        return session;
    }

解决方案

Phill has the right answer, but to take it a little further take a look at http://nhibernate.info/blog/2009/03/13/an-improvement-on-sessionfactory-initialization.html for serializing the NHibernate configuration to a file, so you don't have to rebuild it every time you start the app. This may or may not be a little faster depending on various factors (principally, number of mappings you have) - pursuant to this, Is there any data on NHibernate vs Fluent NHibernate startup performance?

Just to emphasize (based on some of your followup qns in answer-comments), you should be serializing the (NHibernate.Cfg.)Configuration object, not the SessionFactory.

Then, you use the Fluently.Configure(Configuration cfg) overload to inject the config when creating your FluentConfiguration (instead of having it automatically build one for you).

这篇关于流畅nHibernate慢启动时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆