I'm using fluent nHibernate as ORM and mapping the classes using auto mapping in fluenthibernate.The classes would be mapped only once as i'm calling them in global.asax .For some reason the CPU is spiking up to high 90% sometimes .I profiled the application using ANTS performance profiler and found that the Configure() property is consuming 5% of cpu and buildsessionfactory() which calls the automapper is consuming 20% of the CPU.I debugged the application and cannot find what the problem is .What might be the problem ?
Here is my code
public static ISessionFactory GetSessionFactory()
{
lock (factorylock)
{
if (_sessionFactory == null)
{
string scriptLocation = HttpContext.Current.IsDebuggingEnabled
? HostingEnvironment.MapPath( ConfigurationManager.AppSettings["GetDataBaseScript"] )
: null;
FluentConfiguration config = Fluently
//// Start the configuration
.Configure() **--- This is the place where 5% of memory is being used**
// Setup the database configuration
.Database(
// Configure for MS SQL Server connection
MsSqlConfiguration
// use MS SQL Server 2010
.MsSql2008
// Specify the connection string
.ConnectionString(c => c.FromConnectionStringWithKey("DatabaseConnection"))
)
// Set up the mappings
.Mappings( maps =>
maps
Setup mappings
.AutoMappings
// Load mappings from assembly
.Add( AutoMap
// Load auto maps configuration from assembly
.AssemblyOf<AutoMapConfiguration>(new AutoMapConfiguration() )
// Specify some custom conventions for Auto Map
.Conventions.AddFromAssemblyOf<AutoMapConfiguration>()
// Override some automapping configuration
.UseOverridesFromAssemblyOf<AutoMapConfiguration>()
)
);
// determine if we need to generate the DB or just build the configuration
if( !String.IsNullOrEmpty( scriptLocation ) ) {
// Where to generate the script file
// Expose the configuration
config.ExposeConfiguration( c => {
// Export the schema
new SchemaExport( c )
// Specify where the script is to be exported
.SetOutputFile( scriptLocation )
.Create( true, false );
} );
} else {
// Build the configuration
config.BuildConfiguration();
}
// Return the NHibernate Session Factory
_sessionFactory = config.BuildSessionFactory(); **--- This is the place where 20% is being used**
}
return _sessionFactory;
}
}