我正在使用Nhibernate作为asp.net应用程序的OR / M工具,启动性能非常令人沮丧。问题的一部分肯定是我缺乏理解,但我已经尝试了一些(理解肯定在改善),我仍然无处可去。
目前,ANTS探查器的配置()需要13-18秒,而BuildSessionFActory()需要大约5秒。根据我的阅读,这些时间实际上可能相当不错,但他们通常会谈论数百个映射实体......这个项目只有10个。
我已将所有映射文件合并到一个hbm映射文件中,这确实改进了一些事情,但仅限于上述时间......
我想,有没有经常错过的“年轻球员的陷阱”......很明显“我做了这个/你启用了/排除文件x /标记文件y为z”等等......
我会尝试序列化配置事物以避免配置()阶段,但我觉得那部分实体的部分不应该那么长,因此基本上会隐藏当前的问题...
我会在必要时发布源代码或配置,但我不确定要放入什么......
谢谢堆!
修改(更多信息)
我还要补充一点,一旦完成,每页都非常快......
配置代码 - 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
答案 0 :(得分:1)
尝试更改NHibernate记录器的日志记录级别。看来你把它设置为DEBUG,这可能对你的应用程序来说很好。但是会导致NHibernate进行大量的日志记录。
<log4net>
....
<logger name="NHibernate">
<level value="ERROR"/>
</logger>
</log4net>
答案 1 :(得分:1)
您是否尝试从配置中删除与缓存相关的代码?
另外,您是否尝试过使用NHibernate和Castle的最新主干版本?