title: how to increase web app performance with asp.net mvc3 and nhibernate
body: <p>I'm develop my first application using mvc3 nhibernate orm layer with mssql db. </p>
  
  <p>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.</p>
  
  <p>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. </p>
  
  <p>Is that time that session factory must init all "stuff" that needs but I tnink it must be something else. This is unacceptable.</p>
  
  <p>My app is running on winhost on Site Memory Allocation 200 MB, so I think this is not the problem. </p>
  
  <p>Any hints are welcome. If you need more details please ask. </p>
  
  <p>Thanks</p>
  
  <p><strong>Update:</strong>
  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. </p>
  
  <p><strong>Second update:</strong>
  global.asax </p>
  
  <pre><code>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();
  
  }
  </code></pre>
  
  <p>I'm using fluent approach in mapping my objects. So my session provider in domain project looks like this</p>
  
  <pre><code>//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 =&gt; c.FromConnectionStringWithKey(conStringName)))
                  .Mappings(m =&gt; m.FluentMappings.Add&lt;Entity1&gt;())
                  .Mappings(m =&gt; m.FluentMappings.Add&lt;Entity2&gt;())
                  .Mappings(m =&gt; m.FluentMappings.Add&lt;Entity3&gt;())
                  .ExposeConfiguration(p =&gt; p.SetProperty("current_session_context_class", "web"))
                  .BuildConfiguration();
  
              return cfg.BuildSessionFactory();            
          }
  </code></pre>
  
  <p><strong>Update 3</strong>
  Still no solution for this problem</p>
  
  <p><strong>Update 4 and final</strong>
  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.</p>