Tôi đang sử dụng Nhibernate là công cụ OR/M cho một ứng dụng asp.net và hiệu suất khởi động thực sự bực bội. Một phần của vấn đề chắc chắn là tôi trong sự thiếu hiểu biết của tôi nhưng tôi đã cố gắng một chút công bằng (sự hiểu biết chắc chắn là cải thiện) và vẫn không nhận được hư không.nhibernate cấu hình và buildsessionfactory thời gian
Hiện tại trình thu thập thông tin ANTS có Cấu hình() mất 13-18 giây và tệp BuildSessionFActory() mất khoảng 5 giây. Từ những gì tôi đã đọc, những lần này có thể thực sự khá tốt, nhưng họ thường nói về hàng trăm khi hàng trăm thực thể được ánh xạ ... dự án này chỉ có 10.
Tôi đã kết hợp tất cả các tệp ánh xạ vào tập tin bản đồ hbm duy nhất và điều này đã cải thiện mọi thứ nhưng chỉ xuống thời gian được đề cập ở trên ...
Tôi đoán, có bất kỳ "bẫy cho cầu thủ trẻ" thường xuyên bị bỏ lỡ ... hiển nhiên "Tôi đã làm/có bạn đã bật/loại trừ tệp x/đánh dấu tệp y là z "v.v ...
Tôi sẽ thử sắp xếp thứ tự cấu hình để tránh giai đoạn Configure(), nhưng tôi cảm thấy phần đó không dài cho số lượng thực thể đó và vì vậy woul d cơ bản được cất giấu một vấn đề hiện tại ...
tôi sẽ gửi mã nguồn hoặc cấu hình nếu cần thiết, nhưng tôi không chắc chắn những gì để đưa vào thực sự ...
nhờ đống!
chỉnh sửa (thêm thông tin)
Tôi cũng sẽ thêm vào đó một lần này được hoàn thành, mỗi trang là vô cùng nhanh chóng ...
cấu hình số- 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>
lớp học của tôi SessionManager đó là bị ràng buộc và không bị ràng buộc trong một HttpModule cho mỗi yêu cầu
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
chỉnh sửa 2 (kết quả log4net)
sẽ gửi bit rằng có một phần thời gian giữa họ và sẽ cắt bỏ phần còn lại ...
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
Vui lòng đăng mã cấu hình của bạn. Thời gian khởi động đó dài hơn nhiều so với những gì tôi đã trải qua. –
Vâng, chắc chắn có điều gì đó sai trái ở đó!Tuy nhiên, như Jamie đã nói, có thể bạn sẽ cần phải đăng mã cấu hình để nhận được bất kỳ trợ giúp hữu ích nào. – UpTheCreek
Một điều bạn có thể muốn làm là cấu hình log4net để bạn có thể xem lại nhật ký nhibernate – UpTheCreek