Showing posts with label Jdbc. Show all posts
Showing posts with label Jdbc. Show all posts

Thursday, December 27, 2007

Hibernate .vs. Pure JDBC

There is a wrong assumption that Hibernate is slower then JDBC, this is not true.
For the tests that I have done I had found that Hibernate performance are not less then Pure JDBC.

I had compared the performance between Hibernate and Pure JDBC for writing 10,000 rows to the DB table, The results are really surprising.

The test run on a single thread which write in a loop the rows in bulk update, the JDBC used batch update processing with prepared statement, the Hibernate run on a single session which flush the inserts to the DB every 100 rows (Bulk Updates).

I had worked with Hibernate 3.0 on a regular Pentium Pentium 4 2.66GHz with 2GB RAM, The DB was remote Oracle 9 DB.

Well are are the surprising, Hibernate and Pure JDBC results are completely the same !!!
Hibernate doesn't have a huge overhead as you expect it to have.

For the results I manage to write 10,000 rows to the DB in 1.5 Seconds !!!

Here are some tips for improve your Hibernate performance are:

  • Try to reduce the number of open and close of hibernate sessions
  • Using Hibernate bulk updates were possible
  • When using Hibernate bulk updates try to separate the SQL Insert/Update/Delete statements to groups, the DB would process this groups faster (For example 20 SQL inserts then 40 SQL updates and then 25 SQL delete statements)

Monday, December 10, 2007

Improve Hibernate performance using Bulk

If your application needs to run under heavy stress you can improve a lot the performance using hibernate by using bulk updates.

Hibernate allow you to to write bulk of several SQL insert statements at one time,
To do it you need to open an hibernate session, write a set of sql insert statements or a set of sql update statements (don't mix the insert and the update statements togther), and call session.flush() this would use the DB capabilities to write bulk of sql statments in efficent way.

Hibernate underneath use something like JDBC Batch to implement the bulk updates.

I succeed to write in this way 10,000 rows in 1.5 seconds in Oracle DB Table on a simple Pentium machine.

Links

 
RSS Feeds Submission Directory