-
Notifications
You must be signed in to change notification settings - Fork 41.2k
Avoid blocking access to EntityManagerFactory in DataSourceInitializedPublisher #14061
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
Comments
The It looks like we need a way of being notified that the |
In my testing, the current call blocks for ~800ms when running our Data JPA sample. That's quite a large window in which some other processing could be done in parallel with the entity manager factory's initialisation. If we can figure out how to do it, the proposed change looks like it'll be beneficial. |
I tried moving the event publication into the
The deadlock can be avoided by using the factory's bootstrap executor (if it has one) to execute the event publication. @jhoeller does that seem like a reasonable approach to you, or is there a better way that we could be doing this? |
The code for these changes and for #13833 are available in this branch of my fork. Here are some numbers for starting the Data JPA sample on my laptop in Eclipse. Each entry is the average JVM running time of starting the app 10 times:
|
Looks good to me. We have seen the improvements to take even more effect rising with the number of entities in the system, i.e. the longer the EMF needs to build as that might allow even all application components to bootstrap just while the EMF finishes initialization. Dave's (admittedly esotheric) sample app containing a couple of thousand entities and repositories could be brought down from > 70 seconds to just slightly over 10. |
Previously, we would retrieve the EntityManagerFactory’s DataSource as soon as it was being post-processed. When the native EntityManagerFactory is being bootstrapped asynchronously, this retrieval would block until bootstrapping had completed. This negated some of the benefits of asynchronous bootstrapping. This commit updates DataSourceInitializedPublisher so that it only accesses the EntityManagerFactory’s DataSource once its bootstrapping has completed. This is achieved using a decorated JpaVendorAdapter that is called one the boostrapping has completed. Closes spring-projectsgh-14061
By migrating to 2.3.5 we now having issues with MOCK tests. |
@sforner405 We've had a few problems in this area unfortunately but we hoped we'd straightened things out in 2.3.5. If that's not the case for you, can you please open a new issue and provide a small sample that reproduces the hang in your tests with a mock web environment? |
During our optimization efforts in JPA bootstrapping we stumbled above
DataSourceInitializedPublisher.publishEventIfRequired(…)
callingEntityManagerFactory.getProperties()
.In case of an asynchronously bootstrapped
EntityManagerFactory
this will cause the initialization to block and prevent the container from continuing to initialize other components. I wonder it there was a way to rather consume theDataSource
by inspectingEntityManagerFactoryInfo.getDataSource()
as method calls to this interface do not trigger the blocking.The text was updated successfully, but these errors were encountered: