views:

162

answers:

2

Hi all, i'm testing fluent-nhibernate in a small project. I have near 10 classes and when I call BuildSessionFactory method I get a slow response of about 4500ms (too much for a project that runs in about 40ms)

I have identified that the longest method call is Configuration.AddDocument(xxx) in the NHibernate assembly.

I don't set use_reflection_optimizer so I suppose the problem is in my configuration (I hope).


This is what I get..

2009-11-02 17:32:04,171 [7] INFO NHibernate.Cfg.Environment - NHibernate 2.1.1.4000 (2.1.1.4000)

2009-11-02 17:32:04,456 [7] INFO NHibernate.Cfg.Environment - Bytecode provider name : lcg

2009-11-02 17:32:05,234 [7] INFO NHibernate.Dialect.Dialect - Using dialect: NHibernate.Dialect.MsSql2008Dialect

2009-11-02 17:32:07,240 [7] INFO NHibernate.Cfg.XmlHbmBinding.Binder - Mapping class: ImpelSystems.Model.GestioneInterruzioni.FuoriServizio -> FuoriServizio

2009-11-02 17:32:07,304 [7] INFO NHibernate.Dialect.Dialect - Using dialect: NHibernate.Dialect.MsSql2008Dialect

2009-11-02 17:32:07,306 [7] INFO NHibernate.Cfg.XmlHbmBinding.Binder - Mapping class: ImpelSystems.Model.GestioneInterruzioni.RegistroUtenti -> RegistroUtenti

So it's ok to have about a second for startup... but then the first class is mapped in 2 seconds. I'm only trying to search why....

+1  A: 

Building the session factory might be optimized by 1 or 2 seconds, but cannot use NHibernate for an application that must startup a fraction of a second. Most applications using NHibernate run as webapplication or as a service. For this kind of applications a few seconds more or less do not matter, but for you application, I'm afraid that hand build sql is the only thing that will be fast enough.

Paco
+1  A: 

NHibernate does much of its mapping work during the creation of the SessionFactory. By doing mapping and query translation during startup, the costs are not paid each time a Session is created. This is why the recommendation when using NHibernate is to create the SessionFactory only once per application lifetime.

As @Paco mentioned, if you need very fast startup NHibernate may not be the best choice for this application.

Sean Carpenter