-->
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.  [ 30 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Performance improvements
PostPosted: Mon Aug 02, 2004 7:36 am 
Newbie

Joined: Tue May 25, 2004 3:22 pm
Posts: 18
Hi everyone.

I'm in the final stage of developing web-based CMS application, and came across performance issues. I wonder if I went the wrong way.

Application uses Struts + Hibernate + AS400. It is multitiered in terms of that it has stricltly separated layers (BO(businecc objects), DA(data access), TM(transaction management in terms of "application transactions") etc..)

I have a service among others that uses ThreadLocal to hold the current Session instance, just like described in the Hibernate reference.

Having that application separated in layers I have chosen to use the second approach for using Session instances described in the reference:

Everitime I need to read/insert/update/delete something I obtain the session object from my service, perform some actions and call session.close().
This way, it is impossible (I think) to have lazy initialization for parent entities in the app. I've desided not to load all the graph (because this is not necessary and impact performance a lot) but instead to read what I need right from the db, for instance:

If I have some entity that must be presented on the web page, but it has lots of resources and I only need some of them on the page. I have implemented the following method:

EntityResource getMediaResource(Entity parent, String resourceName) {
////obtain Session instance from the service
Query q = session.createQuery("from EntityResource er where er.parent.id=? and er.name=?");
q.setLong(0, parent.getId().longValue);
q.setString(1, resourceName);
List result = q.list();
if (result.size()>0)
entityResource = (EntityResource)result.get(0);

//// skipped exception handling

So this is basically the idea. On the page there might be 5-10 entities with 2-4 types of resources each and I call the above (and alike for other types of resources) method for every entity to form a web page.

I skipped also that each entity can have different resources of the same type and name (this is multi language support - this application going to support 10-20 domains (such as www.test.com, www.test.us, www.test/ru etc.. and give localized content for each requested url))

the other approach was to call something like:
parentEntity.getEntityResources() and iterate them until I get the needed resource (of needed type, name and localization). But as I mentioned earlier, I have 5-10 entities on the page with 2-4 types of resources each.

So my question is did I do right or wrong going the first approach?
How heavy performance impact has session.close() and then using it again? Does the new read opens new JDBC connection?

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 02, 2004 9:30 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
close session once per request, you can do it in filter. Performance problems in data access code are caused by "slow" queries in most of web applications, find most expensive queries and tune db.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 02, 2004 9:55 am 
Newbie

Joined: Tue May 25, 2004 3:22 pm
Posts: 18
Thanks for the suggestion. I'll probably do so. But can someone also answer the questions as well?

I don't have a good understanding of what really happens when I acquire a Session instance through ThreadLocal (is new JDBC Connection opened, is it taken from the pool, how "heavy that process is...)
What happens when I call session.close()?

So that's why I don't know whether I've chosen the right way of retrieving necessary children right from the DB instead of iterating through all the children of the parent...


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 02, 2004 10:17 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
if we are talking about this site http://www.test.com/index.htm then you do not need to care about this stuff, as I understand it is readonly site and it is updated by single person (content manager), generate this content offline and upload plain HTML on server, some script on crontab can connect to dabase and update content daily.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 02, 2004 10:27 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
BTW, I forgot to recommend my favorite optimization for content management systems. If it is too expensive to change app to use offline content generation then you can use filter for content cache. I am not sure, but it looks like https://oscache.dev.java.net/ has this feature.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 02, 2004 10:28 am 
Newbie

Joined: Tue May 25, 2004 3:22 pm
Posts: 18
:))))))

No actually.

Well, I didn't know the test.com even exists!

Well, I'm developing this CSM system for a well known company and I didn't mention their name here for known reasons, just put hypotetical test.com.

I have almost finished it and have to fine tune the performance now. But was just like "whoa, maybe i did it wrong way". I'm sorry, but I think those questions I asked in my previous posts just aren't covered in depth in your reference. I understand that this is open source, I'm not complaining. Just asked. If someone could save me some time diggin' through Hibernate code - it'd be highly appresiated.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 02, 2004 10:38 am 
Newbie

Joined: Tue May 25, 2004 3:22 pm
Posts: 18
Just wanted to add that your optimization suggestion is not acceptable for me unfortunately.

No offline generation.

By the way, do you have info concerning whether Hibernate can support around 1000 concurrent users? I'm going to build cluster with Tomcat but not sure if that amount of users is not too much for Hibernate...


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 02, 2004 10:45 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Surely not. Hibernate is just a tool, it depends how you use it. Hibernate has a small overhead compared to direct JDBC calls (transactional object state, etc.), but can do optimizations you really need for this kind of scale, e.g. flexible caching.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 02, 2004 10:50 am 
Newbie

Joined: Tue May 25, 2004 3:22 pm
Posts: 18
Thanks, thought so... :)

But how about my questions? Anyone?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 02, 2004 11:51 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
I am not sure I understand your question, but if you close session once per request then you will not have any scalability problems and can you to tune it later (content cache is very usefull for things like dynamic menu items, news), but global cache can be a good optimization too (try to tune data access without any cache first). Offline content generation is the best way to optimize web application (velocity templates can help to generate content), 1000 users must not be a problem on single PC for quasy offline content management system without clusters, plain Apache on FreeBSD never fails.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 02, 2004 12:06 pm 
Newbie

Joined: Tue May 25, 2004 3:22 pm
Posts: 18
I understand that. but that's not an issue. The content is generated on-the-fly and I don't have the time for moving my app which is almost done to generate offline content. The deadline is almost met.

It's also a pity (at least for me, since I prefer a strict separation of application layers having developed and participated in a number of serious applications) to be forced moving session handling to a filter. I understand it's the appropriate solution for the majority of web applications consisting of more then just couple o' pages.

I just would like to know if I have chosen a good approach retrieving children from db(see the above posts) or I should've used plain iteration over parent's children...


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 02, 2004 12:12 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
The filter offers you exactly this, a strict separation of concerns. It's an interceptor. Don't get irritated by the word "Servlet", if you don't like it, implement an interceptor system yourself.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 02, 2004 12:49 pm 
Newbie

Joined: Tue May 25, 2004 3:22 pm
Posts: 18
Thanks for that. I'm gonna do so.

But sorry for my persistence :) actually I'm curious as to what is overhead of opening and closing the session in the same request multiple times (keeping in mind that the session is stored using ThreadLocal variable...)

I found the similar topic with interesting questions but nobody helped the guy:

http://forum.hibernate.org/viewtopic.ph ... ion+filter

thanks again,

Igor.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 02, 2004 1:24 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
There is no big overhead as long as your pool is properly configured. A Session is a lightweight object.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 17, 2004 4:14 am 
Newbie

Joined: Mon Jun 21, 2004 6:18 am
Posts: 15
What is the properly configuration for DBCP pool in this case?

My problem is that the first time someone access to the web it is very, very slow, but the next times that person ( of another one ) access the web, it is Ok. Why?

Thank you very much!!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 30 posts ]  Go to page 1, 2  Next

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.