I'm develop my first application using mvc3 nhibernate orm layer with mssql db.
This is my first application created with using nhibernate and everything is fine except intiial responsn time. After some investigations I'm implemented session per web request, which is definitely an upgrade, my entities are loaded much faster after first call, but my problem remains the same.
Initial response time is really slow, when I type domainname.com and hit enter lwaiting time is approx. 10-15 sec. and this is not actual loading time of content, after that time 10-15 sec. my site is starts to load, few more sec.
Is that time that session factory must init all "stuff" that needs but I tnink it must be something else. This is unacceptable.
My app is running on winhost on Site Memory Allocation 200 MB, so I think this is not the problem.
Any hints are welcome. If you need more details please ask.
Thanks
Update: After examing application session usage with nhibernate profiler I found some interesting stuff. Since I'm really a begginer in using profiler I think I found expensive session. IN general statistics 67 entities are loaded in 36.571 duration in seconds. This seconds value is really strange cause I have 10-max 15 sec to load.
Second update: global.asax
public class MvcApplication : System.Web.HttpApplication{
public static ISessionFactory SessionFactory =
MyDomain.Infrastructure.SessionProvider.CreateSessionFactory();
//My session factory is open in Application_Start() like this
SessionFactory.OpenSession();
}
I'm using fluent approach in mapping my objects. So my session provider in domain project looks like this
//This should be used from web app, global.asax.cs calls
public static ISessionFactory CreateSessionFactory()
{
string conStringName = "ConnectionString";
var cfg = Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2008
.ConnectionString(c => c.FromConnectionStringWithKey(conStringName)))
.Mappings(m => m.FluentMappings.Add<Entity1>())
.Mappings(m => m.FluentMappings.Add<Entity2>())
.Mappings(m => m.FluentMappings.Add<Entity3>())
.ExposeConfiguration(p => p.SetProperty("current_session_context_class", "web"))
.BuildConfiguration();
return cfg.BuildSessionFactory();
}
Update 3 Still no solution for this problem
Update 4 and final My problem is definitilly in sessionFactory. I think that my configuration object should be serialized. If anyone can be kind enough to show how to do it using my code showed here with fluently conf. I will gladlly accept his/her answer. Thanks.