[心缘地方]同学录
首页 | 功能说明 | 站长通知 | 最近更新 | 编码查看转换 | 代码下载 | 常见问题及讨论 | 《深入解析ASP核心技术》 | 王小鸭自动发工资条VBA版
登录系统:用户名: 密码: 如果要讨论问题,请先注册。

[备忘]spring里aop匹配性能问题的几个文章

上一篇:[备忘]aspectj和jdk的版本关系
下一篇:[备忘]CMS碎片化promotion failed导致的超长时间GC

添加日期:2024/5/30 11:07:15 快速返回   返回列表 阅读106次

------------------
https://bugs.eclipse.org/bugs/show_bug.cgi?id=532033

@Around("execution(@com.example.demo.Permissions * com.example..*Controller.*(..))")
这种很多*号的,匹配性能问题

举例,以下一些类,方法超级多
com.fasterxml.jackson.databind.ObjectMapper (part of spring-boot-starter-web, 201 methods), org.apache.cxf.jaxrs.JAXRSServerFactoryBean (84 methods), 
com.mchange.v2.c3p0.ComboPooledDataSource (216 methods) 
org.camunda.bpm.engine.spring.SpringProcessEngineConfiguration (485 methods)
匹配耗时

底下的人,回复修改了,自动测试OK,但是spring的自动测试不OK,哈哈,不过这是2019年的事了。
------------------
https://github.com/spring-projects/spring-framework/issues/32262
然后这里,也提到org.springframework.aop.support.AopUtils#findAdvisorsThatCanApply性能问题

由于是单线程,类多,aop多时,耗时很壮观。
他自己改成多线程,快很多,所以建议。

下面大佬说,多线程不好处理结果顺序之类的。
然后关注AspectJ 1.9.21.1的性能改进
后来又出了1.9.22版本。
-------------------------------
https://blog.yangxiaochen.com/blog/stackoverflow/spring-aspectj-slow.html
aop匹配太慢,
@Pointcut("execution(* com.lianjia.xxx.platform.*.dao..*.*(..))" )
卡顿2分钟,

主题是加入within来过滤包,进而减少method级别的匹配。

一般来说, 切面声明有以下集中类型

1. Kinded designators, 比如 execution, get, set, call, handler. 特定类型代码的切面
2. Scoping designators, 比如 within, withincode. 一组切面, 包含了多种类型的代码, 但是有一个范围.
3. Contextual designators, 比如 this, target, @annotation. 可能需要切面的上下文来帮助进行匹配检测.
单独使用 Kinded designators 或者 Contextual designators 都是可以完成功能的, 但可能会影响织入性能, 因为要做额外的处理和分析.

Scoping designators 可以非常快的判断目标是否在范围内, 避免不必要的分析处理.

所以通常写切面定义时, 最好加上 Scoping designators.

最后, 我把切面定义修改为:

@Pointcut("within(com.lianjia.xxx.platform..*) && execution(* com.lianjia.xxx.platform.*.dao..*.*(..))" )
结果界面无效, 因为我要切的目标是 mybatis 的 mapper, 因为这个 mapper 实际上是 com.sun.proxy.Proxy 对象. 最终改成

@Pointcut("within(com.sun.proxy..*) && execution(* com.lianjia.xxx.platform.*.dao..*.*(..))" )
或者

@Pointcut("!within(org.jooq.impl..*) && execution(* com.lianjia.xxx.platform.*.dao..*.*(..))" )
-------------------------------

https://stackoverflow.com/questions/4690860/spring-aop-slow-startup-time
随便看看

https://github.com/eclipse-aspectj/aspectj/issues
aspectj的issues地址


 

评论 COMMENTS
没有评论 No Comments.

添加评论 Add new comment.
昵称 Name:
评论内容 Comment:
验证码(不区分大小写)
Validation Code:
(not case sensitive)
看不清?点这里换一张!(Change it here!)
 
评论由管理员查看后才能显示。the comment will be showed after it is checked by admin.
CopyRight © 心缘地方 2005-2999. All Rights Reserved