-->
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.  [ 33 posts ]  Go to page Previous  1, 2, 3  Next
Author Message
 Post subject:
PostPosted: Sun Jun 13, 2004 3:29 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
lneelaka wrote:
Quote:
You cleared the db cache between each iteration??? I doubt that. Remember, the first iteration will populate the cache.


There are no multiple iterations here. The query is run just once. What I mean't to say is that I ran the test multiple times and before each run I would clear the DB cache to get realistic measures.


Your test is absolutely worthless then. Please learn about benchmarking Java before blaming Hibernate. Read up on how the hotspot engine works. Really.....




Quote:
Quote:
For a system with no concurrency, performance of simple queries is irrelevant


I hear this in every thread where same one dares measure simple selects and inserts. In my application, and in many others, it is very relevant. When we need to process 250 - 400 million rows for multiple queries this adds up to hours ! Stored procedures is not an option for various reasons.

Perhaps you find it strange that such applications even consider Hibernate as an option :)


Correct, we don't recommend ORM for this usecase. We recommend stored procedures.




Quote:
I also noticed that the execution of the statement on the database has a lot to do with the difference in the speed. Hibernate generates a PreparedStatement whereas in this case JDBC is issuing a regular statement. The execution time on DB difference is around 60 % - this accounts for a significant difference in the time measured.


Oh gawd, so you were benching Statement vs PreparedStatement for a single execution of the query??? Statement is always faster in that case. PreparedStatement dominates when the query is executed many times. Really, you shouldn't be doing silly benchmarks if you don't understand basic JDBC. Hibernate is not optimized for such trivial benchmarks, it is optimized for real highly concurrent server-side applications.



Quote:
Quote:
P.S. Note that for this test case, Hibernate is pretty much guaranteed to actually beat direct JDBC, since you can use the query cache. Call Query.setCacheable(true), and set hibernate.cache.use_query_cache.


This didn't benefit me in this use case because I run the query just once.


Conclusion: Hibernate is not optimized for use in applications that run queries once.

duh.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 13, 2004 5:12 pm 
Beginner
Beginner

Joined: Mon Jun 07, 2004 4:21 pm
Posts: 44
Location: Boston
Quote:
Your test is absolutely worthless then. Please learn about benchmarking Java before blaming Hibernate. Read up on how the hotspot engine works. Really.....


I don't think it was worthless - at least not for my app. The 200 % difference - after I did the changes - was when Statement was being measured against PreparedStatement.

When PreparedStatements in JDBC are measured against Hibernate ( which always issues PreparedStatements) the difference is 60 %. In this scenario I ran around 20 iterations of the query - varying one of the parameters in the prepared statement.

Perhaps if I run many, many iterations - at least the minimal required for PreparedStatments to catch up with Statements and then more for Hibernate optimization to kick in - Hibernate may reach the JDBC realm.

I just want to convince myself it does.

Quote:
Correct, we don't recommend ORM for this usecase. We recommend stored procedures.


Seems to me If I can prove to myself that the overhead is in the region of 10-15 % based on all the tests that we do there is no reason why Hibernate should not be an option. As I said - in our case StoredProcedures cannot be considered. The choice is between JDBC and anything else.


Quote:
Conclusion: Hibernate is not optimized for use in applications that run queries once.


Of course. The question is how many times must the query be typically executed before Hibernate pays off? That is by no means obvious and I would think any application should evaluate that.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 13, 2004 5:16 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Do you understand how HotSpot works? If you don't, don't do anymore benchmarks until you do.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 13, 2004 8:08 pm 
Beginner
Beginner

Joined: Mon Jun 07, 2004 4:21 pm
Posts: 44
Location: Boston
Quote:
Do you understand how HotSpot works? If you don't, don't do anymore benchmarks until you do.


I don't claim to be an expert on HotSpot but I do understand the basics.
Secondly - I evaluating an existing application - not providing a benchmark. But parts of it may be useful to others.

I'm quoting below an interview you gave javaperformnacetuning - http://www.javaperformancetuning.com/ne ... w041.shtml

Quote:
Well, we do have one seemingly easy way judge our performance: we can compare Hibernate performance against the equivalent JDBC. Now, it turns out that this test can be misleading. Some important performance optimizations (for example, the transaction-level cache) can actually reduce performance for the kind of very trivial benchmarks that people typically write. This is more a problem of the triviality of the benchmarks than anything else.


It appears that my test cases are similiar to this. I cannot help it - I have to compare with existing code in our application.

Quoting you again:

Quote:
JPT: How did you define a suite of performance testing tools?

We have some standard performance tests that I run regularly, all of which compare Hibernate against handcrated SQL/JDBC. But again, they turn out to be quite unhelpful in practice.


I ran these same tests - and that was my first post. These show JDBC to be 5 times faster in some cases.

The keyword you use is "unhelpful in practice" - you do not state the results are wrong. Can you blame someone for doing the tests in a similiar way - especially after reading this interview?

I would suggest you stop putting down everybody who shows unfavorable results.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 13, 2004 8:31 pm 
Pro
Pro

Joined: Mon Sep 08, 2003 4:30 pm
Posts: 203
Quote:
I would suggest you stop putting down everybody who shows unfavorable results.


Welcome to Gavin's world :)


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 13, 2004 8:35 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Quote:
I would suggest you stop putting down everybody who shows unfavorable results.


Well listen, I am trying not to put you down, but so far you have taken up more than an hour of my time with a silly benchmark that

(1) showed no awareness of the impact of HotSpot (namely that Java code runs faster the more times you execute it)
(2) showed no awareness of the difference between Statement and PreparedStatement
(3) compared JDBC code that read some data and then did nothing with it, against some Hibernate code, that not only returned the results into a list, but also added it to the session-level cache (I showed you how to avoid that overhead using "select new Foo(...) ...")
(4) probably has various other problems (you have not shown any information about session handling, connection pooling, etc)

I mean, it would be difficult to design a more flawed benchmark if I tried.

What you are forgetting here is that I actually know what the true overhead is, since I have spent many hours doing benchmarking work. Don't you get frustrated when someone comes and tries to argue with you about something when you know they are wrong. What about if you had to have this same argument approximately once a month every month??

Lets add up the cumulative improvements already:

(1) use of select new: 100% difference
(2) fair test of PreparedStatement: 50%ish difference on top of that
(3) actually do something with the data in the JDBC test 20% difference
(4) do stuff in a long enough loop to take advantage of HotSpot opimizations: x% improvement (20 may or may not be enough)

If I'm not mistaken, we are now down in about the 10%-20% range. I have no idea what other "buried treasure" waits to be discovered.

Oh, and

(5) take advantage of query caching: y% improvement

Now Hibernate is actually faster than JDBC.

To be brutally honest, would rather just ignore your flawed benchmark and get on with more serious work. Unfortunately, I have to respond to your benchmark since otherwise otherwise other people will read this thread and think it is correct.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 13, 2004 9:39 pm 
Beginner
Beginner

Joined: Mon Jun 07, 2004 4:21 pm
Posts: 44
Location: Boston
Quote:
(1) showed no awareness of the impact of HotSpot (namely that Java code runs faster the more times you execute it)


That is incorrect.
I applied the same environmental conditions to JDBC and Hibernate. I didn't see the need to prepare favorable conditions for one or the other.

Quote:
(2) showed no awareness of the difference between Statement and PreparedStatement


Wrong again. I do have a good understanding of this. I expected that in some situations Hibernate is clever enough to use Statements.

Quote:
I mean, it would be difficult to design a more flawed benchmark if I tried


You already have. Check out your Junit test for performance.

Quote:
What you are forgetting here is that I actually know what the true overhead is, since I have spent many hours doing benchmarking work. Don't you get frustrated when someone comes and tries to argue with you about something when you know they are wrong. What about if you had to have this same argument approximately once a month every month??


Indeed I would get frustrated. I totally sympathise with you. What I would do though is (a) either write a benchmark and point everyone to it or (b) Utilise this opportunity to guide someone to help you write this benchmark

Secondly, nowhere have I been arguing. I have only been attempting to verify things for myself. This does not mean I do not trust you - but I need to understand the inner details.

Quote:
1) use of select new: 100% difference
(2) fair test of PreparedStatement: 50%ish difference on top of that
(3) actually do something with the data in the JDBC test 20% difference
(4) do stuff in a long enough loop to take advantage of HotSpot opimizations: x% improvement (20 may or may not be enough)


For the record, at the end of the first three steps I stated that JDBC is 60 % faster that Hibernate in this query.

I have not verified (4) and the query Cache - but I don't see any reason to doubt the expected performance .

Quote:
To be brutally honest, would rather just ignore your flawed benchmark and get on with more serious work. Unfortunately, I have to respond to your benchmark since otherwise otherwise other people will read this thread and think it is correct.


I am glad you responded. Because the alternative would have been to go by your flawed Junit performance tests.

I've said this before - I'll say this again. I like Hibernate. I just have to go through my tests to make sure it suits our application. And it is not a typical ORM application - but I still think Hibernate will be useful in it.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 14, 2004 5:02 am 
Newbie

Joined: Tue Jun 08, 2004 12:04 am
Posts: 12
Guys - cool down.

May be I shall share my experience about my recent evaluation of Hibernate?

In my recent POC, this is what I've found out:

Hibernate is a fantastic ORM tool. It just depends on how you make usee of it. In our case, we are trying to remove most of our handcoded JDBC code and push things onto Hibernate.

Our situation looks bad enough - hundreds of tables, mostly denormalized, plus high volumes of data movement, with a few layers of DAO and etc.

About performance - I guess this might not be the most important thing that Hibernate is bringing to the table. Nevertheless, we still see very convincing results, because we are able to refactor out some of the hand-coded JDBC code. We achieved significant performance gain.

The most important thing that Hibernate brought us, is reduced system complexity, so the code is simpler, more organized and elegant.

I see that this topic here being focused on is purely about performance. I feel this might not be appropriate. Of course, projects often have a SLA tied to it. However, corporate IT projects is not just about system performance. I think we do have to consider other aspect like system complexity and managibility as well. On this end, I think Hibernate does excel.

If one is looking for an absolute performance king, may be one should consider writing highly optimized C code and does direct database access. I mean, I could hardly see anything that is faster.

Since we are choosing Java, and Hibernate (which is yet another layer again) I guess may be the better question to ask is, "is hibernate fast enough" or "is the simplicity brought to me by this ORM tool enough for me to sacrifice some performance, in terms of overhead?"

I understand why Gavin is upset. I do have to agree with Gavin that the test environment that is being described is not entirely highly concurrent and etc that the Hibernate product is design to excel in.

May be the tester can consider rerunning the benchmark in the context of the entire use-case? (Get the data, do something with it, etc) Then Gavin's concern might not have been so significant and the benchmark can be closer the the real life setting. I feel that, in that case, both you guys get a win-win situation.

Please consider.

A very happy Hibernate user,
Rob


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 14, 2004 7:50 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
totally agree with rsoo,
instead of thinking only about performances, just really think about what ORM is. Just read chapter 1 of hibernate in action to know when ORM might be used.

I think it is the best way for an app to let people think about business more than facade, ejb, base layers, or jdbc layer....
What i see is that one year ago Hibernate was already an excellent ORM.

One year later, i think we can say that it is the best, Toplink is also a great product but i love hibernate (and the team ;)) why?
Because they are able to waste 1 hour to teach you why and how things are without using commercial lies.
They are best pratices teachers!

I think Hibernate is mature, everybody is talking about Hibernate (read about ejb 3.0 for example).
So knowing that it is one the best ORM tools, you shouldn't talk about performance. If you need ORM, Hibernate is the most performant tool you need!

And last word about concurrency, add a security layer, a versionning layer, a transaction management layer upon your JDBC tests, and give us YOUR overhead.

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 14, 2004 8:41 am 
Beginner
Beginner

Joined: Mon Jun 07, 2004 4:21 pm
Posts: 44
Location: Boston
I agree in principle with rsoo and Anthony.

I stated right at the beginning that performance is only one of the issues in an ORM tool.

Again, the application I am evaluating Hibernate for is not a classical fit for ORM. It has a domain model, it does a fair amount of business logic, it even has concurrency. And yet it is not a classical ORM application. For instance - it does not benefit much from caching. It does not benefit much from associative fetching. So you see - even if Hibernate fails in my scenario, it may not be Hibernate's fault.

What I'm venturing to prove here is that despite all this Hibernate may fit our application. If it does, this app may prove to be an exciting advertisement for applications that are not classically ORM apps.

I have a few other tests that shows Hibernate in good light - I have not been able to present that yet...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 15, 2004 3:21 pm 
Beginner
Beginner

Joined: Mon Jun 07, 2004 4:21 pm
Posts: 44
Location: Boston
Here's a non-trivial query that I ran in JDBC and Hibernate:

"select claims, cpt4_cpt4group from Claims as claim, Cpt4Cpt4group as cpt4_cpt4group left outer join cpt4_cpt4group where {fn concat(rtrim(claim.cpt4),\'X\')}=cpt4_cpt4group.cpt4RecType and claim.patientid= :patientid' order by claim.patientid, service.fromdate";

Hibernate was around 5% faster than JDBC.

I ran this for 100 patients. In reality, this query will be executed a few million times. Based on my observations I expect that - if anything, Hibernate should be better in that scenario.

I have also not applied any Hibernate optimizations that will help it perform better - because just these results are acceptable to me. Anything more is a gain.

The database was local to my machine. That is how some of our customers run it - for various reasons.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 16, 2004 1:16 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
Quote:
Wrong again. I do have a good understanding of this. I expected that in some situations Hibernate is clever enough to use Statements.

Why do you think this workaround can be usefull for all users ? Implement wrapper for driver and do all workarounds you like, I do it this way too. It will be possible to reuse this code in any framework or to remove workarounds after you will upgrade driver.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 16, 2004 7:44 am 
Beginner
Beginner

Joined: Mon Jun 07, 2004 4:21 pm
Posts: 44
Location: Boston
In general, PreparedStatements take around 50 iterations and beyond to catch up with Statement objects. I'm sure every application has some SQL which is not executed that many times and they would rather prefer Statements in that scenario and PreparedStatements everywhere also.

This would have been useful in Hibernate for my app. This may not be a big deal for other classical ORM apps.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 16, 2004 9:28 am 
Beginner
Beginner

Joined: Mon Jun 07, 2004 4:21 pm
Posts: 44
Location: Boston
and PreparedStatements everywhere else.

sorry about the typo.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 16, 2004 3:14 pm 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
Quote:
In general, PreparedStatements take around 50 iterations and beyond to catch up with Statement objects.

If your SQL is not executed that many times then you have nothing to optimize, it has no weight .


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 33 posts ]  Go to page Previous  1, 2, 3  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.