-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 11 posts ] 
Author Message
 Post subject: nHibernate - way too slow & memory leaks on web applicat
PostPosted: Thu Feb 01, 2007 10:14 am 
Newbie

Joined: Mon Nov 20, 2006 3:58 am
Posts: 12
Hi all,

we just recently completed and deployed our first e-commerce website on the net with ASP.NET and C#.NET with nHibernate 1.2.0.1001 and MS SQL 2000 on another shared Server. and its way too slow.

we were expecting it to be slow due to its architecture but the biggest surprise is huge jumps in memory requirements. Even a single web page request consume like 20+MB.. and when you have like 5 - 6 users it become painfully slow. It start giving out of memory errors.

As it is just the new database there are not much records in it and code base is not huge either.. entire code takes up around 7 - 8 MB. So we just don't know why it is leaking so much memory.

The w3wp.exe file which is the IIS worker process and gets kicked in as soon as anybody access the site starts at around 70MB.. and with each new page connection it jumps like 20MB.. and within mins with hardly half a dozen users we are looking at 250MB.. and the worst part is that even after all the user leave the memory stays at 250MB and if somebody comes after like even half n hour the memory will jump from 250 to 270MB.. whereas it should have released all the earlier memory before requesting for the newer memory.

I sure believe that we have missed some optimization techniques plus as the SQL Server is on another server it is opening too many connections and may not be closing them timely. and the objects are not getting destroyed after they leave the scope.

We thought of adding GC.Collect after each page load but we have not implemented it yet because its i think going to put unnecessary stress on the server cpu usage.

So i will greatly if you can point me to some documentation for making the nHibernate faster and more efficient and ways to regain the lost memory without losing the session variables.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 01, 2007 10:29 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
The most frequent source of such problems is building a new session factory for each request. Check that you are not doing it.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 01, 2007 10:55 am 
Newbie

Joined: Sun Nov 05, 2006 10:19 am
Posts: 13
I had (and have) the same problem as you.....The difference between me and you is that I reached also 500MB......(with lazy to true)....

Anyway the only solution that I've found so far was to buy more memory to be sure the server is up :D .... That's a solution too :)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 01, 2007 5:42 pm 
Beginner
Beginner

Joined: Thu Dec 21, 2006 11:38 am
Posts: 30
I would recommend NOT putting a GC.Collect() on each page.

There has to be some other code thats causing this memory leak.

Like sergey said, recreating SessionFactories on every request could be the culprit. Building a new SessionFactory is an expensive process, and typically only needs to be done once in an Application.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 02, 2007 1:27 am 
Newbie

Joined: Mon Nov 20, 2006 3:58 am
Posts: 12
Lorelai wrote:
I had (and have) the same problem as you.....The difference between me and you is that I reached also 500MB......(with lazy to true)....

Anyway the only solution that I've found so far was to buy more memory to be sure the server is up :D .... That's a solution too :)


We have 4 GB memory on Intel Xeon dual socket and dual core system. meaning 4 core/threads can run simultaneously at 3.0 Ghz. I think it should be enough..


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 02, 2007 1:58 am 
Newbie

Joined: Mon Nov 20, 2006 3:58 am
Posts: 12
sergey wrote:
The most frequent source of such problems is building a new session factory for each request. Check that you are not doing it.


I just tested our data layer from which we are making every DAL in the project and i found this code.
Code:
            try
            {
                cfg = new NHibernate.Cfg.Configuration();
                cfg.Configure();

                factory = cfg.BuildSessionFactory();
                session = factory.OpenSession();
                transaction = session.BeginTransaction();
            }
            catch (NHibernate.ADOException ex)
            {
                rollback();
                DALDBException myDALDBException = new DALDBException(ex);
                throw myDALDBException;
            }
            catch (NHibernate.HibernateException ex)
            {
                rollback();
                DALHibernateInternalException myDALHibernateInternalException = new DALHibernateInternalException(ex);
                throw myDALHibernateInternalException;
            }
            catch (Exception ex)
            {

                rollback();
                DALException myDALException = new DALException(ex);
                throw myDALException;
            }

I attached a breakpoint on the first line of the try statement and found that even on the main page it is getting called 5 times... which means that we are building session factory for each request. is there a way where we can restrict the session factory from building multiple times without doing lot of code changes?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 02, 2007 3:02 am 
Beginner
Beginner

Joined: Mon Jan 08, 2007 11:59 pm
Posts: 31
You can find your answer here

http://www.hibernate.org/363.html

Basically create your factory from a singleton class and use a HttpModule to create and dispose session at request begin and end respectively.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 02, 2007 3:58 am 
Newbie

Joined: Mon Nov 20, 2006 3:58 am
Posts: 12
samueljob wrote:
You can find your answer here

http://www.hibernate.org/363.html

Basically create your factory from a singleton class and use a HttpModule to create and dispose session at request begin and end respectively.


Thanks i will go through it.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 06, 2007 4:31 pm 
Newbie

Joined: Wed Jun 06, 2007 4:21 pm
Posts: 3
Same problem with me!

I have a WEBServer Xeon 3.00 GHz with 4GB and a DBServer with the same configuration.

I set sessionstet (SQLState) in my web.config and I have 4 worker processes.They recyle at 750MB.

The webapp on rush hour its very slow.

I am also using Open-Session-In-View pattern http://sourceforge.net/forum/message.php?msg_id=2847509.

NHibernate version 1.2.0.4000

I really need to know if this is normal.

Best regards!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 07, 2007 1:33 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Since we don't have access to your application, we can't really know what part in it is the bottleneck. Try using a profiler.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 07, 2007 7:58 am 
Newbie

Joined: Wed Jun 06, 2007 4:21 pm
Posts: 3
Dear Sergey,

So do you think there is something wrong?

What should be the common memory usage for the w3wp.exe in a web app.?

If my session is not inProc, what could be (general talking) the cause of the memory usage if I have all in lazy=true and my session factory open and close per request?

If an object is saved in memory by the Castle Dynamic Proxy how long will stay in it? Do I have the chance to tell it not to use all my memory? Let say, use only a cache within 2GB or 3GB?

Does anybody can open my mind about the relation between Nhibernate and w3wp.exe ?

What about people in this post with the same problem? Did you solve this issue?

Thank you so much.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 11 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.