We have just finish to profile our application. ( she’s begin to be slow ). the problem seems to be “in hibernate”.
It’s a legacy mapping. Who work’s, and do it’s job. The relational shema behind is ok too.
But some request are slow as hell.
So, we would appreciate any input on common and usual mistake made with hibernate who end up with slow response.
Exemple : Eager in place of Lazy can change dramaticly the response time….
Edit : As usual, read the manual is often a good idea. A whole chapter cover this subject here :
One of the most common pitfalls is the infamous
n+1 selects problem
. By default, Hibernate doesn’t load data you didn’t ask for. This reduces memory consumptions but exposes you to the n+1 selects problem which can be avoided by switching to the right fetching strategy to retrieve all the data you need to load objects in their appropriately initialized state.
But also don’t fetch too much or you’ll run into the opposite problem, the cartesian product issue
: instead of executing to many SQL statements, you may end up creating statements that retrieve too much data.
That’s the whole point of the tuning: finding the middle between not enough and too much data for each use case of your application (or at least, for the one that require to be tuned).
- first activate SQL logging at Hibernate’s level
- run the critical use cases (the 20% used 80% of the time) or even all of them if you have that luxury
- identify suspicious queries and optimize the fetch plan, check if indices are used appropriately, etc
- involve your DBA