title: How to speed up my Nhibernate configuration
body: <p>I have a ASP.NET MVC4 web api that uses fluent NHibernate, but when I run debug it takes 1½ min to access any site that uses the database the first time I try, so I found <a href="https://stackoverflow.com/questions/4382870/fluent-nhibernate-slow-startup-time">Fluent nHibernate Slow Startup Time</a> but I am not sure how to utilize that, </p>
  
  <p>When it runs on the live server it must garbage collect the session data as it takes ages to configure again if I havent used it for a long time.</p>
  
  <p>Is it possiible to cut it down to maybe sub 10 seconds instead of 1.5 minutes? </p>
  
  <p>My current SessionFactory class looks like this</p>
  
  <pre><code>public class SessionFactory
  {
      private static readonly string ConnString = System.Configuration.ConfigurationManager.ConnectionStrings["MySQLConnectionString"].ConnectionString;
  
      private static ISessionFactory _session;
      private static readonly object SyncRoot = new Object();
  
      private static ISessionFactory CreateSessionFactory()
      {
          return Fluently.Configure()
              .Database(MySQLConfiguration
              .Standard
              .ConnectionString(ConnString))
              .Mappings(m =&gt; m.FluentMappings
                  .AddFromAssemblyOf&lt;UserMap&gt;())
                  .ExposeConfiguration(UpdateSchema)
                  .BuildSessionFactory();
      }
  
      private static void UpdateSchema(Configuration cfg)
      {
          new SchemaUpdate(cfg).Execute(false, true);
      }
  
      public static ISession Session
      {
          get
          {
              if (_session == null)
              {
                  lock (SyncRoot)
                  {
                      if (_session == null)
                          _session = CreateSessionFactory();
                  }
              }
              return _session.OpenSession();
          }
      }
  }
  </code></pre>
  
  <p>Here is a screenshot of a dotTrace<img src="https://i.stack.imgur.com/gOIih.jpg" alt="enter image description here"></p>
  
  <p>Timing the request on my host it takes 1 min and 50 seconds for the initial request, and thats on "live" server (I cant control the IIS there)</p>