I’m working to upgrade my Hibernate version to 5.3. I’ve noticed that by default the legacy batch fetch style is being used by default (LegacyBatchingEntityLoader).
This style with a default batch fetch size of 50 and in combination with my model which contains hundreds of entities with different proxies is giving me a retained heap of 950 MB by the SessionFactoryImpl class once Hibernate is set up.
However, using the dynamic fetch style this retained size is reduced to 100MB…which is a considerable difference.
I would like to know:
Why is the legacy style the default option?
Do you have any kind of benchmark/recommendations that I can follow to decide which is the best approach to take?
It takes 1.2 M our and there are only 24 instances. However, the heap is 1GB, so I guess it’s the Metamodel that takes so much memory. If you have thousand of classes, you need lot of memory to hold the Metamodel for that.
thanks! Some additional feedback to try to prove my point… this is the memory dump taken from my application before upgrading to Hibernate 5.3:
and this is the heap after the upgrade (the same of my previous post):
Please note the difference between the retained size of the SingleTableEntityPersister instances. In particular, the retained size of each SingleTableEntityPersister is coming from a map where each entry references the mentioned LegacyBatchingEntityLoader.
And In addition, if I change the batch fetch style to “dynamic” instead of using the “legacy” one, I can see that the retained size of the SingleTableEntityPersister is decreased:
@caristu Thanks for letting us know. I’ll send it to the mailing list so we can discuss what might have caused this memory increase and the best way to address it.
I have this problem with both bytecode providers. I first tried with version 5.3.0.CR1 which as far as I know, was using javassist as the default bytecode provider. Now I’ve tried with 5.3.0.CR2 which is using byte buddy as default one and I have exactly the same behavior…
Taking into account such heap differences between fetch styles, I would like to know which are your recommendations in this regard.
How the three different styles (legacy, padded and dynamic) impact at database and java level?
Do you have any benchmark that could help me to choose the most suitable style for my model?
yes I can share the dumps without trouble. How can I send them to you?
Besides, I would like to share with you the following changeset[1], for your consideration. It helped us to reduce the heap when using Hibernate 3.6. But it seems to be not enough after the upgrade to Hibernate 5.3.
The idea would be to import in the test case all the model related to the entity FinancialMgmtAccountingCombination (i.e. this particular entity and all its relations). Not sure how much work it would be but that would be very helpful for us to play with your case and see how we can improve things with a real use case in mind.
ok, I would appreciate if you could keep me in touch about your progress in this situation.
Regarding your suggestion about using the dynamic strategy, have you measured/compared the differences when switching between the strategies?
It would be great if you could share any kind of benchmark (in case you have) that could help us to determine how this slow down can impact us. Do you also know how this change can affect us in terms of garbage collection?
I’ll try to extract that part of the model to be able to send you a test case, but it can take me some time.
Finally, have you been able to check the changeset I provide in my previous response? Do you think if it could make sense to include it in Hibernate?
Regarding your suggestion about using the dynamic strategy, have you measured/compared the differences when switching between the strategies?
Not really. What you can also do is reducing the batch size to something like 5. It should reduce by ~ a third the number of EntityLoaders per LegacyBatchingEntityLoader and it should help.
For now, I have identified the EntityLoaders as the culprit.
I insist a bit because that would be really helpful to improve the situation. I saw you work at OpenBravo so I thought maybe I could get the sources and do the work myself but the sources I found seem to be very old and I couldn’t find the files by browsing the Mercurial UI (I haven’t checked out the repo though).