Performance issue at OpenMRS 2.3.0 startup HibernateSessionFactoryBean / DefaultAdvisorAutoProxyCreator

Hello, we have noticed a performance issue at OpenMRS startup (version 2.3.0): 13 minutes is sometimes required. I have cleaned and rebuilt our modules, docker,… and checked that lucene indexation is not launched.

I started OpenMRS using the Visual VM profiler and here are some results ( still under investigation). The profiler gives:

With the debugger I found that the error is mainly Error creating bean with name 'sessionFactory': FactoryBean which is currently in creation returned null from getObject and it’s generating in the method org.openmrs.module.ModuleUtil#refreshApplicationContext when the Spring Context is refreshed (org.springframework.context.support.AbstractApplicationContext#refresh) and the errors occurs mainly when org.springframework.context.support.AbstractApplicationContext#initMessageSource is called.

It seems that ( sorry I won’t be clear here :slight_smile: ):

the advisor org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator is called when a MessageSource object is created, it’s intercepted by a TransactionInterceptor, … and then we ended with a situation where some objects are created too early in the refresh action.

Here is modification I check: replace the DefaultAdvisorAutoProxyCreator by a custom ProxyCreator to skip auto-proxying (org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator#shouldSkip) for some bean classes ( MessageSource, ResourceBundleThemeSource).

Thanks to this OpenMRS starts in 7 min.

Currently I don’t know the whole impact of these modifications :slight_smile: and if I really on the root cause of the performance issue… Does someone have some feedback ?

Of course, I could propose a PR and create a ticket concerning this point.

This type of very technical change is probably best discussed in a PR. I like the idea of doing this to speed-up the start-up time though!

Yes i also agree with @ibacher that, create a ticket and corresponding pull request. We shall review, test, and provide feedback.

Thanks again for investing time in improving the startup speed even more, in addition to what @wolf has already done for us in the upcoming 2.4.0 platform. Amazing work done by Wolf Schlegel for the OpenMRS Platform!

Hello in fact it “seems” we have this performance issue since we use the version 2.15 of appframework-api instead of 2.14. I believe I was trying to fix some consequences of this modification.

in 2.15 some new advises has been introduced and maybe could be a good start to search

FYI, in our application, we have > 15k locations but it doesn’t seem to be the cause of the slowness. The new advice is not called during the Spring context refresh which is the longer part.