No, it wasn't because of connection opening and closing. Actually all the data was already in cache, so it wasn't even trying to connect. In a loop I was calling Session.Reconnect, then getting an object by id and calling Session.Disconnect. Reconnect was very cheap, while Disconnect was 1000 times slower. Most of the time - 99.93% - was eaten by AfterTransactionCompletion method. Most expensive of its callees are:
- 32.87% - SequenceHashMap.OrderedEnumerator.MoveNext;
- 28.22% - ...OrderedEnumerator.get_Current;
- 5.96% - EntityEntry.set_LockMode;
Each of those methods are not expensive by itself, but they were called around 8000 times per one call to Disconnect.
Here is the detailed trace:
Code:
100,00% Disconnect - 99074 ms - 4330 calls - NHibernate.Impl.SessionImpl.Disconnect()
99,93% AfterTransactionCompletion - 99009 ms - 4330 calls - NHibernate.Impl.SessionImpl.AfterTransactionCompletion(bool)
32,87% MoveNext - 32562 ms - 33667076 calls - NHibernate.Util.SequencedHashMap.OrderedEnumerator.MoveNext()
10,29% get_Next - 10195 ms - 67329822 calls - NHibernate.Util.SequencedHashMap.Entry.get_Next()
28,22% get_Current - 27962 ms - 33662746 calls - NHibernate.Util.SequencedHashMap.OrderedEnumerator.get_Current()
5,64% get_Value - 5591 ms - 33662746 calls - NHibernate.Util.SequencedHashMap.Entry.get_Value()
5,96% set_LockMode - 5901 ms - 33662746 calls - NHibernate.Impl.EntityEntry.set_LockMode(LockMode)
0,03% Debug - 30 ms - 4330 calls - log4net.Core.LogImpl.Debug(Object)
0,01% Log - 9 ms - 4330 calls - log4net.Repository.Hierarchy.Logger.Log(Type, Level, Object, Exception)
0,01% IsEnabledFor - 7 ms - 4330 calls - log4net.Repository.Hierarchy.Logger.IsEnabledFor(Level)
0,00% IsDisabled - 3 ms - 4330 calls - log4net.Repository.Hierarchy.Hierarchy.IsDisabled(Level)
0,00% get_Configured - 1 ms - 4330 calls - log4net.Repository.LoggerRepositorySkeleton.get_Configured()
0,00% get_Threshold - 0 ms - 4330 calls - log4net.Repository.LoggerRepositorySkeleton.get_Threshold()
0,00% get_EffectiveLevel - 1 ms - 4330 calls - log4net.Repository.Hierarchy.Logger.get_EffectiveLevel()
0,00% get_Logger - 2 ms - 4330 calls - log4net.Core.LoggerWrapperImpl.get_Logger()
0,02% get_Values - 15 ms - 4330 calls - NHibernate.Util.IdentityMap.get_Values()
0,01% get_Values - 11 ms - 4330 calls - NHibernate.Util.SequencedHashMap.get_Values()
0,01% ctor - 6 ms - 4330 calls - NHibernate.Util.SequencedHashMap.ValuesCollection.ctor(SequencedHashMap)
0,00% ctor - 1 ms - 4330 calls - System.Object.ctor()
0,01% Clear - 13 ms - 4330 calls - System.Collections.ArrayList.Clear()
0,01% GetEnumerator - 12 ms - 4330 calls - NHibernate.Util.SequencedHashMap.ValuesCollection.GetEnumerator()
0,01% ctor - 6 ms - 4330 calls - NHibernate.Util.SequencedHashMap.OrderedEnumerator.ctor(SequencedHashMap, ReturnType)
0,00% ctor - 1 ms - 4330 calls - System.Object.ctor()
0,01% MoveNext - 6 ms - 4330 calls - System.Collections.ArrayList.ArrayListEnumeratorSimple.MoveNext()
0,01% GetEnumerator - 6 ms - 4330 calls - System.Collections.ArrayList.GetEnumerator()
0,03% CloseConnection - 30 ms - 38 calls - NHibernate.Impl.SessionFactoryImpl.CloseConnection(IDbConnection)
0,03% CloseConnection - 30 ms - 38 calls - sdf.Persist.Hibernate.SdfConnectionProvider.CloseConnection(IDbConnection)
0,03% Close - 27 ms - 38 calls - System.Data.SqlClient.SqlConnection.Close()
0,00% get_ConnectionProvider - 0 ms - 38 calls - NHibernate.Impl.SessionFactoryImpl.get_ConnectionProvider()
0,00% get_ConnectionProvider - 0 ms - 38 calls - NHibernate.Cfg.Settings.get_ConnectionProvider()
0,02% Debug - 15 ms - 4330 calls - log4net.Core.LogImpl.Debug(Object)
0,01% Log - 9 ms - 4330 calls - log4net.Repository.Hierarchy.Logger.Log(Type, Level, Object, Exception)
0,01% IsEnabledFor - 8 ms - 4330 calls - log4net.Repository.Hierarchy.Logger.IsEnabledFor(Level)
0,00% IsDisabled - 3 ms - 4330 calls - log4net.Repository.Hierarchy.Hierarchy.IsDisabled(Level)
0,00% get_Threshold - 1 ms - 4330 calls - log4net.Repository.LoggerRepositorySkeleton.get_Threshold()
0,00% get_Configured - 1 ms - 4330 calls - log4net.Repository.LoggerRepositorySkeleton.get_Configured()
0,00% get_EffectiveLevel - 1 ms - 4330 calls - log4net.Repository.Hierarchy.Logger.get_EffectiveLevel()
0,00% get_Logger - 0 ms - 4330 calls - log4net.Core.LoggerWrapperImpl.get_Logger()
0,00% CloseCommands - 1 ms - 38 calls - NHibernate.Impl.BatcherImpl.CloseCommands()
0,00% GetEnumerator - 0 ms - 76 calls - Iesi.Collections.DictionarySet.GetEnumerator()
0,00% GetEnumerator - 0 ms - 76 calls - System.Collections.Hashtable.KeyCollection.GetEnumerator()
0,00% get_Keys - 0 ms - 76 calls - System.Collections.Hashtable.get_Keys()
0,00% Clear - 0 ms - 76 calls - Iesi.Collections.DictionarySet.Clear()
0,00% Clear - 0 ms - 76 calls - System.Collections.Hashtable.Clear()
0,00% MoveNext - 0 ms - 76 calls - System.Collections.Hashtable.HashtableEnumerator.MoveNext()