metrics-spring
metrics-spring copied to clipboard
AdvisingBeanPostProcessor can call excessively AopUtils.canApply which can lead to performance issue when using Spring prototypes
Our application heavily rely on the following pattern:
@Component @Scope(BeanDefinition.SCOPE_PROTOTYPE)
public class Prototype { ... }
@Inject
private Provider<Prototype> prototypeProvider;
public Prototype getPrototype() {
return prototypeProvider.get();
}
each time we instantiate the Prototype object, the AdvisingBeanPostProcessor is getting called and eventually test wheter we can apply AOP on that prototype class using AopUtils.canApply(pointcut, targetClass)
The implementation of AopUtils.canApply is really heavy weight, it has to drill down in each available methods of the target class which can then lead to performance issue.
I do not know if there would be any ways to optimize the pattern? My initial thought is just to create a Map to store wheter if for a given pointcut + targetClass if the check has already been done. WDYT? Finally, if you think this is the only way, I can provide a pull request with a potential fix.
Thanks,
Oh interesting, I didn't realize it hit prototype scoped beans so hard. My only concern is the memory usage of that cache. If only Java had a builtin LFU cache. I've pushed a possible fix: https://github.com/ryantenney/metrics-spring/tree/can-apply-cache. Would you be able to test it and see if there's an improvement?
I should be able to test soon if this resolved our issue. I'll keep you updated but I'm very confident with your proposed fix.
We performed a stress test yesterday with your proposed fix an the issue is definitly gone.
Thanks so much!
Hi @ryantenney , I was just wondering, do you know when this fix will become mainstream in the 3.1.x branch?
Thanks!
Hi @ryantenney , well… I have basically the same question as @matlach: are you planning to release a v3.1.4 with that fix so we can simply update our maven dependencies? Would be awesome! Thanks a lot!
Hi @ryantenney , any update on this? Thanks!
@efasel I'm sorry I haven't gotten this fix out! I'll cut a release this week.
Hi @ryantenney ! :-)
Two month ago you wrote:
I'm sorry I haven't gotten this fix out! I'll cut a release this week.
Obviously something has come up, but maybe you'll have time soon? Would be great to have a release including this important fix. Thanks!
Best regards, Elmar
That was 2 months ago? I'm sorry for keeping you waiting. My personal laptop died and took with it the key I need to sign the release. I'll find a backup and get a release out soon.
Hi @ryantenney, sorry to hear that your laptop died. I hope you didn't lose anything important. Any plan to do this release we're talking about soon? :-) Best regards, Elmar
Hi @ryantenney, what about a nice Christmas present for the community and have a v3.1.4 release? :christmas_tree: :gift: ? :smiley: Best regards, Elmar
I just got my laptop back from Apple yesterday ;) coming right up
:tada:
Hi @ryantenney ! I just saw that you created a tag for v3.1.4 but this was not released to the usual maven repositories. So – as far as I know – we cannot simply update our dependency:
[WARNING] The POM for com.ryantenney.metrics:metrics-spring:jar:3.1.4 is missing, no dependency information available
Are you planning on pushing v3.1.4 as an official release?
Hi @ryantenney! How are you today? Just wanted to ask regarding the 3.1.4 release … :-)