-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Quarkus slow Hibernate startup - Property hard coded on FastBootHibernatePersistenceProvider #16927
Comments
hi @leonardowestphal , no this is an internal property and it's not currently meant for end users to try overriding it. Could you explain why you think this particularly property is responsible for the slow loading? Also, could you try and see how fast it loads when you're configuring the application exclusively using the Generally speaking, the use of |
Hi @Sanne , is the same problem related in some Hibernate issues. For example:
And for the reason that I mentioned, Quarkus is loading metadata when registering and initializing QuarkusStaticDialectFactory. I'm migrating a legacy system that needs to manually define the desired entities, so I need to do this using persistence.xml. Unfortunately in this case I cannot use the 'hibernate.archive.autodetection' property. Also, from what I noticed, not all properties used by the legacy system can be configured through application.properties Used properties(I have not yet evaluated which ones I will be able to remove/change): One more question. How can I override the password using Quarkus with persistence.xml? So that it's not hard coded on persistence.xml |
Can you help me? Why is it not possible to change the value of the 'hibernate.temp.use_jdbc_metadata_defaults' property ? |
I resolved it with this PR: #17509 |
This is probably a duplicate of #15888 |
May also be resolved with #17509 |
@leonardowestphal could you confirm if you see slow startup even when setting (The Quarkus property is https://quarkus.io/guides/hibernate-orm#quarkus-hibernate-orm_quarkus.hibernate-orm.database.generation ) We should be able to bypass the cause of the slowdown when the schema validation is turned off. |
As a separate check (do not do in combination with skipping validation), could you also test setting This setting controls whether Hibernate will access the JDBC |
one more request: please capture some stacktraces in the slow configuration, hopefully identifying the stack in which we have to wait for multiple minutes. |
I will perform these requested tests... I don't know if this helps, but I noticed that the slowness in my case is due to loading of UDTs: https://www.postgresql.org/docs/9.5/xtypes.html Using Squirrel SQL client I can disable this type of metadata loading and then everything is faster when using this tool. |
This is exactly the point I resolved with this PR: #17509. Using the value false everything is fast! |
That's fantastic news, we can easily do something about it. |
This should avoid loading all UDT and all keywords, w/o needing to set any property - and without causing problematic side-effects: Could you try it @leonardowestphal ? To build it locally, run |
None is the default value for Quarkus, however I performed the test using this property in application.properties and it's still slow. (I've already eliminated the use of persistence.xml) The startup "freezes" a long time in "JDBC driver metadata reported database stores quoted identifiers in neither upper, lower nor mixed case" Logs (I removed some sensitive data):
|
I think you nailed it above. If you have a lot of UDT mappings then that part of startup could conceivably take a long time. I had added this for a feature I always wanted to come back and implement, but its not implemented and that method is just an unneeded overhead at the moment. Sanne already implemented some changes to this code I suggested. |
@leonardowestphal I've updated my experiment at hibernate/hibernate-orm#4043 . I'm afraid the version I had pushed earlier today was still possibly loading those same objects, this should be better. I really can't test it as my databases don't show this problem, I hope you could try it. Also if you can, please share a stacktrace of when it's waiting - that would be much more useful than a log for us to know what exactly is the problem in your case. For example forcing a threaddump while it's waiting. |
I've tested it with version 5.5.1-SNAPSHOT and the total time has been reduced about 20 seconds, but it's still slow (1+ minute). I hope this stacktrace is enough:
|
Very interesting, thanks! So it's sequence details; it gets a bit more complicated but let's see what we can do. Can you give us an idea of how many sequences you have in the database, and show how a typical entity is mapped to use them? |
There are about 100,000. It's a little scary, but this high number is due to a legacy solution. An example:
|
Would it be feasible to create a specific property to allow not loading the metadata of the sequences? Or maybe something similar... to be less comprehensive than property 'hibernate.temp.use_jdbc_metadata_defaults' and decrease the risks involved. |
Yes we can introduce that; I'll look into it. Thanks for all details! |
Thanks @Sanne |
@leonardowestphal I have another draft for you and hope you could test it :) you'll have to set the Hibernate configuration property If this works, I'll cleanup the code and merge it in ORM, then patch Quarkus to always set this flag. |
@Sanne Thank you! |
nice, thanks to you for all the quick testing and details :) So, we did a couple of things. The In another area of the code, during bootstrap when loading the Furthermore, I've noticed that these checks are redundant if you have schema validation enabled: the schema validator will also check for the same mistakes and throw an exception. I do assume and recommend people that deploy in production / staging to use the schema validation - or if they don't to take good care that the code is matching the schema expectations - so that kinda makes this flag redundant and that's why I believe it should be disabled in Quarkus: you'll still have this validated when you enable schema validation - and when you don't enable schema validation, we will trust you on that choice. In short, this disables loading of the sequence metadata but it doesn't fully disable the other things we need from And sure we'll start the backporting process; I'm not really sure which release train this will be able to catch - so can't promise it being included in the very next maintenance release, but it shouldn't take too long. |
I've been watching this from the sidelines and I just wanted to say thank you @Sanne for explaining things so thoroughly (and it was not the first time you took the time to do so). Really appreciated! |
I'm immensely grateful for all the answers and the great help you have given me. Now we can proceed with our project with the certainty that these issues have been overcome. Thanks again for all your support. |
My pleasure :) and many thanks also to @sebersole , @yrodiere and @dreab8 who helped with it too. |
Thank you guys! |
quarkus/extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/FastBootHibernatePersistenceProvider.java
Line 192 in 9c73b17
When using Quarkus '1.13' on Dev mode the application start up get slow on Hibernate loading metadata (A very large Postgres database. Total start up time: 5 minutes and 30 seconds). The line of code 192 on class FastBootHibernatePersistenceProvider overrides the property 'hibernate.temp.use_jdbc_metadata_defaults' defined on persistence.xml. Is it possible to change this behavior so the application can start fast?
I have two persistence units on persistence.xml. Hibernate initializes both without the metadata, but when Quarkus registers and initializes 'QuarkusStaticDialectFactory' Hibernate uses metadata on org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator (line of code 65) because it is set hard coded on 'FastBootHibernatePersistenceProvider' overriding persistence.xml.
I'm in doubt if it is a bug or it is really necessary for Quarkus.
It seems that Hibernate is initializing the PUs and Quarkus is causing Hibernate to load again due to the use of QuarkusPostgreSQL95Dialect.
The text was updated successfully, but these errors were encountered: