Maybe you are 100% sure that this is a connection pool problem, but I have to ask. How do you know for sure that you are running out of connections in the connection pool? Are you using performance counters to make sure the pool size is maxed out? What is the exception is the logs when you "run out of connections"? All of this data is helpful as well.
Sometimes, I have thought that I am having connection pool leaks, when in reality the database server is performing poorly under load (for whatever reason, bad code, missing index, etc). You can run out of connections quickly on a large site when all of a sudden your queries start taking a long time to respond and you have more and more queries coming into the system. The fact that it takes a week to occur is irrelevant in regards to the connection pool because pools have a default timeout, probably something like 60 seconds. On Feb 6, 5:30 pm, Ken Egozi <[email protected]> wrote: > I'm no NH ninja, but brushing over your code these were the points popping > out: > > a. what will happen should > session.Transaction.Rollback() > fail? > > b. what is CurrentSessionContext ? > > c. you might want to switch the check for > HttpContext.Current.Request.Path.ToLower().IndexOf(".aspx") > -1) > into checking whether the current Handler is IHttpHandler (or is Page) > > d. is it possible that you have somewhere a type of request that takes too > long, thus bogging down requests? > > e. I'm not sure, but I think that BeginTransaction will cause an actual > IDbConnection to start it's dance, so it might be better to handle > transactions in actual business context, so that there'll be less > connections, and each will last for a wee bit shorter time > > > > On Fri, Feb 6, 2009 at 11:32 PM, Robin Nadeau <[email protected]> wrote: > > nope. > > > On Fri, Feb 6, 2009 at 4:29 PM, Ayende Rahien <[email protected]> wrote: > > >> Do you have Connection Pooling=False there? Or very small pool size? > > >> On Fri, Feb 6, 2009 at 11:25 PM, Robin Nadeau <[email protected]> wrote: > > >>> You'll understand that all the data in our connectionstring is secret > >>> information, but it does contain the Data Source, the Network Library, > >>> Initial Catalog, User ID and Password. Nothing out of the ordinary. As for > >>> usage, I'll investigate that. > > >>> On Fri, Feb 6, 2009 at 4:15 PM, Ayende Rahien <[email protected]> wrote: > > >>>> What is the connection string? Maybe it was turned off for some reason? > >>>> Do you see gradual increase in the number of users over the week? > > >>>> On Fri, Feb 6, 2009 at 11:11 PM, Robin Nadeau <[email protected]>wrote: > > >>>>> By default connection pooling is enabled in ado .net, so I assume it > >>>>> works the same with NHibernate. We had the default number of > >>>>> connections. > > >>>>> On Fri, Feb 6, 2009 at 4:07 PM, Ayende Rahien <[email protected]>wrote: > > >>>>>> That is one option, certainly. > >>>>>> but, do you have connection pooling enabled? > >>>>>> What is the # of connections in the DB now? > > >>>>>> On Fri, Feb 6, 2009 at 11:04 PM, Robin Nadeau > >>>>>> <[email protected]>wrote: > > >>>>>>> We're using SQL Server 2005. My other theory is that we simply don't > >>>>>>> have enough database connections at peak periods. > > >>>>>>> On Fri, Feb 6, 2009 at 4:00 PM, Ayende Rahien > >>>>>>> <[email protected]>wrote: > > >>>>>>>> Extremely unlikely. > >>>>>>>> If this happens, then the session (and the connection) would go out > >>>>>>>> of scope and would be reclaimed by the GC > >>>>>>>> The finalizer should release the connection anyway. > > >>>>>>>> What DB are you talking about? > > >>>>>>>> On Fri, Feb 6, 2009 at 10:58 PM, Robin Nadeau > >>>>>>>> <[email protected]>wrote: > > >>>>>>>>> I'm using the session-per-request pattern for nhibernate and am > >>>>>>>>> running out of database connections. This takes about 1 week to > >>>>>>>>> occur on a > >>>>>>>>> heavily loaded server, taking about 100,000 hits per day. The code > >>>>>>>>> I use to > >>>>>>>>> manage my session is below. My theory is that the httpsession could > >>>>>>>>> timeout > >>>>>>>>> before the EndRequest event, causing the reference to the session > >>>>>>>>> to be > >>>>>>>>> lost, and therefore no closed. Is that even possible? If so, what > >>>>>>>>> can be > >>>>>>>>> done about it? > > >>>>>>>>> Public Class NHibernateSessionPerRequestModule > >>>>>>>>> Implements IHttpModule > > >>>>>>>>> Public Sub New() > >>>>>>>>> End Sub > > >>>>>>>>> ' In the Init function, register for HttpApplication > >>>>>>>>> ' events by adding your handlers. > >>>>>>>>> Public Sub Init(ByVal application As HttpApplication) _ > >>>>>>>>> Implements IHttpModule.Init > >>>>>>>>> AddHandler application.BeginRequest, _ > >>>>>>>>> AddressOf Me.Application_BeginRequest > >>>>>>>>> AddHandler application.EndRequest, _ > >>>>>>>>> AddressOf Me.Application_EndRequest > >>>>>>>>> End Sub > > >>>>>>>>> Private Sub Application_BeginRequest(ByVal source As Object, _ > >>>>>>>>> ByVal e As EventArgs) > >>>>>>>>> 'Fires when the request begins > >>>>>>>>> Try > >>>>>>>>> If > >>>>>>>>> (HttpContext.Current.Request.Path.ToLower().IndexOf(".aspx") > -1) > >>>>>>>>> Then > >>>>>>>>> Dim session As NHibernate.ISession = > >>>>>>>>> StaticSessionManager.OpenSession() > >>>>>>>>> session.BeginTransaction() > >>>>>>>>> CurrentSessionContext.Bind(session) > >>>>>>>>> End If > >>>>>>>>> Catch ex As Exception > >>>>>>>>> Dim objLoggingController As New > >>>>>>>>> AlertPay.Utilities.LoggingController > >>>>>>>>> objLoggingController.Write("Error in creating > >>>>>>>>> NHibernate Session", "Information", 0, "0", > >>>>>>>>> "NHibernateSessionPerRequestModule") > >>>>>>>>> End Try > > >>>>>>>>> End Sub > > >>>>>>>>> Private Sub Application_EndRequest(ByVal source As Object, _ > >>>>>>>>> ByVal e As EventArgs) > > >>>>>>>>> If > >>>>>>>>> (CurrentSessionContext.HasBind(StaticSessionManager.SessionFactory)) > >>>>>>>>> Then > >>>>>>>>> Dim session As NHibernate.ISession = > >>>>>>>>> CurrentSessionContext.Unbind(StaticSessionManager.SessionFactory) > >>>>>>>>> If Not session Is Nothing Then > >>>>>>>>> Try > >>>>>>>>> session.Transaction.Commit() > >>>>>>>>> Catch > >>>>>>>>> session.Transaction.Rollback() > >>>>>>>>> Dim objLoggingController As New > >>>>>>>>> AlertPay.Utilities.LoggingController > >>>>>>>>> objLoggingController.Write("Error in commiting > >>>>>>>>> NHibernate Session. Rolling back transaction", "Information", 0, > >>>>>>>>> "0", > >>>>>>>>> "NHibernateSessionPerRequestModule") > >>>>>>>>> Finally > >>>>>>>>> If session.IsOpen Then > >>>>>>>>> session.Close() > >>>>>>>>> End If > >>>>>>>>> End Try > >>>>>>>>> End If > >>>>>>>>> End If > > >>>>>>>>> End Sub > > >>>>>>>>> Public Sub Dispose() Implements System.Web.IHttpModule.Dispose > >>>>>>>>> End Sub > > >>>>>>>>> End Class > > >>>>>>>>> -- > >>>>>>>>> Robin Nadeau, B.Eng. > >>>>>>>>> Software Developer > > >>>>>>> -- > >>>>>>> Robin Nadeau, B.Eng. > >>>>>>> Software Developer > > >>>>> -- > >>>>> Robin Nadeau, B.Eng. > >>>>> Software Developer > > >>> -- > >>> Robin Nadeau, B.Eng. > >>> Software Developer > > > -- > > Robin Nadeau, B.Eng. > > Software Developer > > -- > Ken > Egozi.http://www.kenegozi.com/bloghttp://www.delver.comhttp://www.musicglue.comhttp://www.castleproject.orghttp://www.gotfriends.co.il --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nhusers?hl=en -~----------~----~----~----~------~----~------~--~---
