-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Improve performance of DefaultSingletonBeanRegistry.getSingletonNames(..) for high-concurrent-load applications [SPR-7949] #12604
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
mck commented (why can't i edit the description? the first and last thread dumps are identical... (how frustrating...)) |
mck commented Simple patch that changes the mutex to a ReadWriteLock. Subclasses in org.springframework.beans have been rewritten to lock() instead of synchronized. This does change the (internal) API of DefaultSingletonBeanRegistry.getSingletonMutex() so i can understand if this is better suggested for the next major release... |
mck commented This patch (applied to 3.0.5.RELEASE) has been running for 3 weeks in production ( http:/finn.no ) and has successfully fixed spring's poor performance around prototype beans for us. |
ggn commented We are also facing the same issue where numerous threads are blocked on the synchronized block in getSingleton method. Please help. |
1 similar comment
ggn commented We are also facing the same issue where numerous threads are blocked on the synchronized block in getSingleton method. Please help. |
Vladimir Rozhkov commented Have same problems in our environment. Any chance to get this fix in 3.2M2? Also, could we raise priority to Normal? Thanks. |
Vladimir Rozhkov commented Also, why we trying to get singleton instance first, even if bean has prototype scope?
Is there reasons for it? I guess we should consider bean scope first to prevent execution of unnecessary singleton searching. |
Vladimir Rozhkov commented Attached patch doesn't actually fixes the problem. We still have tons of threads locked on writeLock insinde getSingleton. Also, after moving bean definition resolving to the top of the method, we still have lock in
So Spring cannot handle accurately requests to getting prototype beans in 15 concurrent threads with 4000 invocations of getBean in each. This is huge gap. |
Chris Beams commented This issue duplicates #11536, which is now resolved. Please give it a try (available now in 3.2.0.BUILD-SNAPSHOT). |
Uh oh!
There was an error while loading. Please reload this page.
mck opened SPR-7949 and commented
Under high-concurrent load situation, in an application using many prototype beans, contention occurs in DefaultSingletonBeanRegistry.getSingletonNames(..)
This method has uses singletonObjects as a mutex for all map operations.
Using a ReadWriteLock this contention could be removed, as in our case 99% of the calls here are read-only.
We see hundreds of thread dumps like in a single jvm:
java.lang.Thread.State: BLOCKED (on object monitor)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:180)
at org.springframework.beans.factory.support.AbstractBeanFactory.isTypeMatch(AbstractBeanFactory.java:452)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:317)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:296)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:250)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1083)
java.lang.Thread.State: BLOCKED (on object monitor)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingletonNames(DefaultSingletonBeanRegistry.java:277)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:352)
at org.springframework.beans.factory.BeanFactoryUtils.beanNamesForTypeIncludingAncestors(BeanFactoryUtils.java:185)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:829)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:744)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:703)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.resolvedCachedArgument(AutowiredAnnotationBeanPostProcessor.java:436)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.access$0(AutowiredAnnotationBeanPostProcessor.java:432)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:469)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:283)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1074)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBean(AbstractAutowireCapableBeanFactory.java:295)
java.lang.Thread.State: BLOCKED (on object monitor)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:180)
at org.springframework.beans.factory.support.AbstractBeanFactory.isTypeMatch(AbstractBeanFactory.java:452)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:317)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:296)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:250)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1083)
Affects: 3.0.4, 3.0.5
Attachments:
Issue Links:
17 votes, 16 watchers
The text was updated successfully, but these errors were encountered: