Thanks for that - very helpful.

The snapshot is being taken after the request has completed.  Am I the only
one who has a large chunk of unmanaged memory allocated when I use
nhibernate?

*
*
  *Paul Allington [image: See my
profile]<http://www.intelligentpenguin.co.uk/about/theteam/paul>
*
*T:* 01799 522 665
*M:* 07973 145 754
*E:* [email protected]
*W:* www.intelligentpenguin.co.uk
*W:* www.creative-penguin.co.uk
 [image: Intelligent Penguin] <http://www.intelligentpenguin.co.uk>  For
highly creative & technically brilliant websites, and on-line management
systems
------------------------------------------------------------------------------
 My
profiles: [image: Facebook] <http://www.facebook.com/paulallington>[image:
LinkedIn] <http://uk.linkedin.com/in/paulallington>[image:
Twitter]<http://twitter.com/paulallington>
Contact me: [image: Google Talk/]phallington [image:
Skype/]paul-allington [image:
Y! messenger/]paul_allington




On Wed, Feb 9, 2011 at 10:20 PM, John Davidson <[email protected]> wrote:

> The code from Jason will work, but it assumes that the entire session
> happens in one transaction, which probably works in 99% of use cases, while
> the other 1% needs a different management strategy. This can be done by
> ensuring that a commit happens at the end of your first logical work unit
> and that it starts a new transaction for the second work unit.
>
> The other piece to check is that the http module is actually being used. It
> is bound into the aspx pipeline by the web.config file. The Register
> RequestHTTPModule section is important.
>
> Finally there is the question of when and how the memory snapshot is being
> generated. The snapshot needs to be taken when there is no active requests,
> i.e. when a web page has just completed loading, rather than while it is
> loading.
>
>
> On Wed, Feb 9, 2011 at 4:33 PM, Paul Allington <
> [email protected]> wrote:
>
>> Thanks - that's useful, I'll clean up the request code.  Perhaps it's just
>> the way it managed the objects, but it doesn't explain the 30MB of unmanaged
>> memory - this I can't profile.  Any clue what this could be?
>>
>> *
>> *
>>   *Paul Allington [image: See my 
>> profile]<http://www.intelligentpenguin.co.uk/about/theteam/paul>
>> *
>> *T:* 01799 522 665
>> *M:* 07973 145 754
>> *E:* [email protected]
>> *W:* www.intelligentpenguin.co.uk
>> *W:* www.creative-penguin.co.uk
>>  [image: Intelligent Penguin] <http://www.intelligentpenguin.co.uk>  For
>> highly creative & technically brilliant websites, and on-line management
>> systems
>>
>> ------------------------------------------------------------------------------
>>   My
>> profiles: [image: Facebook] <http://www.facebook.com/paulallington>[image:
>> LinkedIn] <http://uk.linkedin.com/in/paulallington>[image: 
>> Twitter]<http://twitter.com/paulallington>
>> Contact me: [image: Google Talk/]phallington [image: Skype/]paul-allington
>> [image: Y! messenger/]paul_allington
>>
>>
>>
>>
>> On Wed, Feb 9, 2011 at 9:05 PM, Jason Meckley <[email protected]>wrote:
>>
>>> I think the problem is your transaction management in end request.
>>> rollback if error (good) else flush session (bad). call transaction.commit()
>>> instead and dispose of the transaction.
>>>
>>> some things to consider:
>>> 1. sessions are cheap so just create one for each request and dispose
>>> when the request ends.
>>> 2. all NH actions should be wrapped in a transaction if every request
>>> will require db access begin/end the transaction with the session. if not
>>> all WCF calls require NH, than manage the transaction with a decorator
>>> around the WCF call (similar to Filters in MVC frameworks)
>>>
>>> I would start by cleaning up the module code
>>>
>>> //begin request
>>> var session = SessionFactory.OpenSession();
>>> session.BeginTransaction();
>>> ManagedWebSessionContext.Bind(HttpContext.Current, session);
>>>
>>> //end request
>>> var session = ManagedWebSessionContext.Unbind(HttpContext.Current,
>>> SessionFactory);
>>> using(session)
>>> {
>>>    using(var tx = session.Transaction)
>>>    {
>>>        if(Server.LastException == null)
>>>        {
>>>             tx.Commit();
>>>        }
>>>        else
>>>        {
>>>            tx.Rollback();
>>>        }
>>>    }
>>> }
>>>
>>> that's it. now if you want to manage the transaction per WCF action then
>>> the module would only manage the session
>>> //begin request
>>>
>>> ManagedWebSessionContext.Bind(HttpContext.Current,
>>> SessionFactory.OpenSession());
>>>
>>> //end request
>>> ManagedWebSessionContext.Unbind(HttpContext.Current,
>>> SessionFactory).Dispose();
>>>
>>> and a WCF decorator would manage the transaction. something like
>>> //decorator... wcfservice is the original/base implementation
>>> using(var txt = SessionFactory.GetCurrentSession().BeginTransaction())
>>> {
>>>     try
>>>     {
>>>         wcfservice.Proceed();
>>>         tx.Commit();
>>>     }
>>>     catch
>>>     {
>>>           tx.Rollback();
>>>           throw;
>>>     }
>>> }
>>>
>>> --
>>> 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.
>>>
>>
>>  --
>> 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.
>>
>
>  --
> 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.
>

-- 
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.

Reply via email to