加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – nhibernate配置和buildsessionfactory时间

发布时间:2020-12-16 03:46:48 所属栏目:asp.Net 来源:网络整理
导读:我正在使用Nhibernate作为asp.net应用程序的OR / M工具,启动性能非常令人沮丧.问题的一部分肯定是我缺乏理解,但我已经尝试了一点(理解肯定在改善),我仍然无处可去. 目前,ANTS分析器的配置()需要13-18秒,而BuildSessionFActory()大约需要5秒.根据我的阅读,这
我正在使用Nhibernate作为asp.net应用程序的OR / M工具,启动性能非常令人沮丧.问题的一部分肯定是我缺乏理解,但我已经尝试了一点(理解肯定在改善),我仍然无处可去.

目前,ANTS分析器的配置()需要13-18秒,而BuildSessionFActory()大约需要5秒.根据我的阅读,这些时间实际上可能相当不错,但他们通常会谈论数百个映射实体……这个项目只有10个.

我已将所有映射文件合并到一个hbm映射文件中,这确实改进了一些事情,但仅限于上述时间……

我想,有没有经常错过的“年轻球员的陷阱”……很明显“我做了这个/你启用了/排除文件x /标记文件y为z”等…

我将尝试序列化配置事物以避免Configure()阶段,但我觉得那部分实体的部分不应该那么长,因此基本上会隐藏当前的问题……

如有必要,我会发布源代码或配置,但我不确定要放入什么…

谢谢堆!

编辑(更多信息)
我还要补充一点,一旦完成,每页都非常快……

配置代码 – hibernate.cfg.xml

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="hibernate-configuration"
    type="NHibernate.Cfg.ConfigurationSectionHandler,NHibernate" />
  </configSections>
  <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
    <session-factory>
      <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
      <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
      <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
      <property name="connection.connection_string_name">MyAppDEV</property>
      <property name="cache.provider_class">NHibernate.Caches.SysCache.SysCacheProvider,NHibernate.Caches.SysCache</property>
      <property name="cache.use_second_level_cache">true</property>
      <property name="show_sql">false</property>
      <property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory,NHibernate.ByteCode.Castle</property>
      <property name="current_session_context_class">managed_web</property>

      <mapping assembly="MyApp.Domain"/>
    </session-factory>
  </hibernate-configuration>
</configuration>

我的SessionManager类,它在每个请求的HttpModule中绑定和解除绑定

Imports NHibernate
Imports NHibernate.Cfg

Public Class SessionManager

    Private ReadOnly _sessionFactory As ISessionFactory

    Public Shared ReadOnly Property SessionFactory() As ISessionFactory
        Get
            Return Instance._sessionFactory
        End Get
    End Property

    Private Function GetSessionFactory() As ISessionFactory
        Return _sessionFactory
    End Function

    Public Shared ReadOnly Property Instance() As SessionManager
        Get
            Return NestedSessionManager.theSessionManager
        End Get
    End Property

    Public Shared Function OpenSession() As ISession
        Return Instance.GetSessionFactory().OpenSession()
    End Function

    Public Shared ReadOnly Property CurrentSession() As ISession
        Get
            Return Instance.GetSessionFactory().GetCurrentSession()
        End Get
    End Property

    Private Sub New()
        Dim configuration As Configuration = New Configuration().Configure()
        _sessionFactory = configuration.BuildSessionFactory()
    End Sub

    Private Class NestedSessionManager
        Friend Shared ReadOnly theSessionManager As New SessionManager()
    End Class

End Class

编辑2(log4net结果)

将发布在它们之间有一部分时间的位,并将删除其余的…

2010-03-30 23:29:40,898 [4] INFO  NHibernate.Cfg.Environment [(null)] - Using reflection optimizer
2010-03-30 23:29:42,481 [4] DEBUG NHibernate.Cfg.Configuration [(null)] - dialect=NHibernate.Dialect.MsSql2005Dialect

2010-03-30 23:29:42,501 [4] INFO  NHibernate.Cfg.Configuration [(null)] - Mapping resource: MyApp.Domain.Mappings.hbm.xml
2010-03-30 23:29:43,342 [4] INFO  NHibernate.Dialect.Dialect [(null)] - Using dialect: NHibernate.Dialect.MsSql2005Dialect
2010-03-30 23:29:50,462 [4] INFO  NHibernate.Cfg.XmlHbmBinding.Binder [(null)] - Mapping class:

2010-03-30 23:29:51,353 [4] DEBUG NHibernate.Connection.DriverConnectionProvider [(null)] - Obtaining IDbConnection from Driver
2010-03-30 23:29:53,136 [4] DEBUG NHibernate.Connection.ConnectionProvider [(null)] - Closing connection

解决方法

尝试更改NHibernate记录器的日志记录级别.看起来你把它设置为DEBUG,这可能对你的应用程序来说很好.但是会导致NHibernate进行大量的日志记录.

<log4net>
  ....
  <logger name="NHibernate">
      <level value="ERROR"/>
  </logger>
</log4net>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读