I'm having performance issue with this ASP.NET app. From SQL Server log there're MANY MANY log which resembles the following:
Code:
SQL Server log: Login succeeded for user 'APPL_ACCOUNT'. Connection: Non-Trusted.
I'm talking thousands in one morning. And I am suspecting that this is the cause of the performance degradation. I thought when you
Code:
conn.Open();
ADO.NET draws from ADO.NET connection pool (REF:
http://www.15seconds.com/issue/040830.htm) using existing connections in the pool and you don't "login" again? Is this assumption right? I ran a very simple test:
Code:
using System;
using System.Data;
using System.Data.SqlClient;
static void Main(string[] args)
{
String s_conn = "Data Source=127.0.0.1;Initial Catalog=pubs;User Id=sa;Password=secret;Max Pool Size=80;Min Pool Size=30;";
IDbConnection oconn;
Int32 i;
oconn = new SqlConnection (s_conn);
for(i=0; i<100; i++)
{
oconn.Open();
oconn.Close();
}
return;
}
This did NOT generate a bunch of "Login succeeded" in my SQL Server's
Server Log. But, the surprise is, there was NOT even ONE "Login succeeded" in my SQL Server's
Server LogBtw, I'm using NHibernate... And the way NHibernate open an ISession (corresponds to a IDbConnection) is as follows:
Code:
Dim _nhibernate_conn_factory ISessionFactory = BuildFactory() 'This is time consuming so we only create it once...
Public Function GetWarehouseNHibernateSession() As ISession Implements IWarehouseConnectionManager.GetWarehouseNHibernateSession
Dim conn As ISession
Dim maxRetry, retryFreq As Int32
Try
conn = nhibernate_conn_factory.OpenSession()
Catch ex As System.Data.SqlClient.SqlException
'handle the exception
Catch ex As Exception
'handle the exception
End Try
Return conn
End Function
My finding is, for each "OpenSession" there's a corresponding entry in SQL Server's log:
"SQL Server log: Login succeeded for user 'APPL_ACCOUNT'. Connection: Non-Trusted."
Is this normal? On one of my page there's 35 OpenSession - seems like this is what's slowing down the application.
From
NHibernate.Impl.SessionFactoryImpl:
Code:
private ISession OpenSession( IDbConnection connection, bool autoClose, long timestamp, IInterceptor interceptor )
{
return new SessionImpl( connection, this, autoClose, timestamp, interceptor );
}
A new session is a NHibernate.Impl.SessionImpl. I'm not sure what to conclude next... how it correlates and trigger:
Code:
IDbConnection.Open()
And how that trigger a
"Login" event on
SQL Server log.
Just one more thing, it seems SessionImpl.Connection is not called during construction, meaning when Session factory OpenSession call (which call SessionImpl constructor), a IDbConnection is NOT created at that time - it's probably created on first Load/Save/Update... on the ISession instance:
Code:
public IDbConnection Connection
{
get
{
if( connection == null )
{
if( connect )
{
connection = factory.OpenConnection();
connect = false;
}
else
{
throw new HibernateException( "session is currently disconnected" );
}
}
return connection;
}
}
Well, don't think this is relevant to the issue at hand... how to reduce number of
"Login succeeded" entries in SQL Server log and improves speed.
Advice? I need this fast!! Thanks Thanks!
ADO.NET Connection pooling REF:
http://www.15seconds.com/issue/040830.htm
NHibernate REF:
http://nhibernate.sourceforge.net/NHibernateEg/NHibernateEg.Tutorial1A.html