Я использую свободный nHibernate как ORM и сопоставляю классы с использованием автоматического сопоставления в fluenthibernate. Классы будут отображаться только один раз, когда я вызываю их в global.asax. По какой-то причине CPU иногда увеличивается до 90%. Я профилировал приложение, используя профилировщик производительности ANTS, и обнаружил, что свойство Configure() потребляет 5% процессора и buildsessionfactory(), которое вызывает automapper, потребляет 20% от CPU.I отлаживает приложение и не может найти, в чем проблема. Какая может быть проблема?Использование Fluen-nHibernate всплесков CPU
Вот мой код
общественного статического 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;
}
}
Я звоню его только во время приложения запуска. – Yoda
То, что я предположил, когда увидел вашу нулевую проверку на _sessionFactory. Если вы профилируете запуск, сколько времени тратится на пространство имен System.XML? Может быть, это может вам помочь. http://ayende.com/blog/2903/real-world-nhibernate-reducing-startup-times-for-large-amount-of-entities – hessenmob82