Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sample persistence.xml for a production instance using jpa2 and hibernate 3.6.x

    <property name="hibernate.generate_statistics" value="true"/>

In a production scenario, it would make sense to switch the above flag to false. What other flags should be modified so that hibernate engine is optimized for a faster speed accessing a MySQL database.

like image 226
Joe Avatar asked Jun 22 '11 03:06

Joe


1 Answers

It depends :) you can set cache sizes, fetch depth (for outer joins), fetch batch sizes and many more things.

You probably don't want to log too much (show_sql => set to false, format_sql => set to false, use_sql_comments => set to false).

But really, it depends and you have to measure.

It is also important to use and properly configure a connection pool. Here again: Use common sense and measure.

Hopefully, these links will prove to be useful:

http://docs.jboss.org/hibernate/core/3.3/reference/en/html/session-configuration.html

http://docs.jboss.org/hibernate/core/3.3/reference/en/html/performance.html

The crucial point is to get the model right. Performance will be an issue if many sql requests are generated that do massive joins. So if performance is critical, you have to spend some thinking on normalization or in fact on NOT doing too much normalization in your entity-relationship modelling.

Also, collections and how you model/handle them can play a big role in terms of performance.

And as far as caching is concerned: Depending on your use case, you can improve performance by great lengths if you configure your second level cache (e.g. Ehcache) properly. That again means: Think about what can be cached and what not and how long-lived and how large your caches can and should be. So it really, reallly depends :)

like image 196
mkro Avatar answered Nov 03 '22 01:11

mkro