确认
当前程序版本
3.5.9
问题描述
项目从3.3.2版本,升级到3.5.9版本之后,项目启动时间翻2倍,当然具体这个启动变慢是从那个版本起就不得而知了,唯一的变量就是mybatis-plus的版本变化,以及相关的特性调整。可能是baseMapper的方法增多导致的,也可能是别的原因,从日志上看,感觉是生成Mapper单例对象的耗时增多了
详细堆栈日志
2024-12-27 01:23:08,934 D o.s.b.f.s.DefaultListableBeanFactory [main] Creating shared instance of singleton bean 'mccInfoLklServiceImpl'
2024-12-27 01:23:08,936 D o.s.b.f.s.DefaultListableBeanFactory [main] Creating shared instance of singleton bean 'mccInfoLklMapper'
2024-12-27 01:23:09,398 D o.s.b.f.s.DefaultListableBeanFactory [main] Creating shared instance of singleton bean 'menuInfoService'
2024-12-27 01:23:09,400 D o.s.b.f.s.DefaultListableBeanFactory [main] Creating shared instance of singleton bean 'menuInfoMapper'
2024-12-27 01:23:10,142 D o.s.b.f.s.DefaultListableBeanFactory [main] Creating shared instance of singleton bean 'memberFollowRecordServiceImpl'
2024-12-27 01:23:10,150 D o.s.b.f.s.DefaultListableBeanFactory [main] Creating shared instance of singleton bean 'memberFollowRecordMapper'
2024-12-27 01:23:10,739 D o.s.b.f.s.DefaultListableBeanFactory [main] Creating shared instance of singleton bean 'merchantComplaintImageServiceImpl'
2024-12-27 01:23:10,740 D o.s.b.f.s.DefaultListableBeanFactory [main] Creating shared instance of singleton bean 'merchantComplaintImageMapper'
2024-12-27 01:23:11,233 D o.s.b.f.s.DefaultListableBeanFactory [main] Creating shared instance of singleton bean 'merchantComplaintRecordServiceImpl'
2024-12-27 01:23:11,235 D o.s.b.f.s.DefaultListableBeanFactory [main] Creating shared instance of singleton bean 'merchantComplaintRecordMapper'
2024-12-27 01:23:11,984 D o.s.b.f.s.DefaultListableBeanFactory [main] Creating shared instance of singleton bean 'merchantMarketServiceImpl'
2024-12-27 01:23:11,986 D o.s.b.f.s.DefaultListableBeanFactory [main] Creating shared instance of singleton bean 'merchantMarketMapper'
2024-12-27 01:23:12,840 D o.s.b.f.s.DefaultListableBeanFactory [main] Creating shared instance of singleton bean 'merchantOrderStatisticsServiceImpl'
2024-12-27 01:23:12,841 D o.s.b.f.s.DefaultListableBeanFactory [main] Creating shared instance of singleton bean 'merchantOrderStatisticsMapper'
2024-12-27 01:23:13,704 D o.s.b.f.s.DefaultListableBeanFactory [main] Creating shared instance of singleton bean 'merchantRejectDescServiceImpl'
2024-12-27 01:23:13,705 D o.s.b.f.s.DefaultListableBeanFactory [main] Creating shared instance of singleton bean 'merchantRejectDescMapper'
2024-12-27 01:23:14,849 D o.s.b.f.s.DefaultListableBeanFactory [main] Creating shared instance of singleton bean 'notificationServiceImpl'
2024-12-27 01:23:14,850 D o.s.b.f.s.DefaultListableBeanFactory [main] Creating shared instance of singleton bean 'notificationMapper'
2024-12-27 01:23:15,872 D o.s.b.f.s.DefaultListableBeanFactory [main] Creating shared instance of singleton bean 'officialGoodsExchangeServiceImpl'
Comment From: LowAndroider
已切到3.4.3.4,启动时间恢复正常
Comment From: nieqiurong
用这工程去测试对比. https://github.com/baomidou/mybatis-plus-samples/tree/master/mybatis-plus-startup-analysis
Comment From: iFoxox
使用了AOP后更慢
Comment From: iFoxox
使用了AOP后更慢
https://github.com/baomidou/mybatis-plus/issues/6516 和这个issue描述的一样,新的版本一旦有AOP启动就非常慢。3.4.3.4版本正常。
Comment From: nieqiurong
使用了AOP后更慢
测试了下只有在jvm内存配置不足的情况下,才会出现说的AOP导致启动慢.
Comment From: nieqiurong
Comment From: nieqiurong
压缩到 -Xms64M -Xmx64M
Comment From: nieqiurong
Comment From: nieqiurong
Comment From: nieqiurong
3.4.3.4版本由于没做堆内存优化, 如果开aop测在64M下测不了,会出现GC overhead limit exceeded
Comment From: iFoxox
3.4.3.4版本由于没做堆内存优化, 如果开aop测在64M下测不了,会出现GC overhead limit exceeded
测试工程脱离用户的具体环境,这点可以理解。但用户环境一般是复杂,一般都会做一些特定的扩展,比如我的工程Controller、Service、Mapper都默认生成几个自定义的方法。使用的是springboot 3.2.4,MP使用不同版本相同bean初始化时间差异明显,上千个bean就多出了十几秒。现在已知的是3.5.9版本jsqlparser单独引入。
Comment From: nieqiurong
你整理个复现工程出来吧,这样猜又猜不到什么.
Comment From: iFoxox
你整理个复现工程出来吧,这样猜又猜不到什么.
https://github.com/iFoxox/testaop
抽出了个简单工程出来,3.5.7.和3.5.9虽然没有很大区别了,但依旧是3.5.9的慢。使用AOP的更慢
Comment From: nieqiurong
把mybatis-spring降级到3.0.3
Comment From: nieqiurong
发现并不是mybatis-spring问题,可能是我那台测试主机波动太大了,换成笔记本来跑这工程,3.5.9和3.5.7并没多少差距. 启动时间对比.xlsx
启用AOP 版本 | | | | | | 平均耗时 -- | -- | -- | -- | -- | -- | -- 3.5.7 | 8961 | 8647 | 8675 | 9549 | 9685 | 9103.4 3.5.9 | 9196 | 9647 | 8368 | 8494 | 8721 | 8885.2 关闭AOP 版本 | | | | | | 平均耗时 -- | -- | -- | -- | -- | -- | -- 3.5.7 | 3950 | 4197 | 4808 | 4342 | 5197 | 4498.8 3.5.9 | 4055 | 3987 | 4660 | 4333 | 4222 | 4251.4Comment From: iFoxox
发现并不是mybatis-spring问题,可能是我那台测试主机波动太大了,换成笔记本来跑这工程,3.5.9和3.5.7并没多少差距. 启动时间对比.xlsx
启用AOP
版本 平均耗时 3.5.7 8961 8647 8675 9549 9685 9103.4 3.5.9 9196 9647 8368 8494 8721 8885.2 关闭AOP
版本 平均耗时 3.5.7 3950 4197 4808 4342 5197 4498.8 3.5.9 4055 3987 4660 4333 4222 4251.4
只能慢慢找了。AOP优化有方向?
Comment From: nieqiurong
@Pointcut("execution(public * com.test.aop.controller...(..))") 把你的切入点改成 @Pointcut("within(com.test.aop.controller..*)")
Comment From: iFoxox
也只能先这样了
Comment From: nieqiurong
https://github.com/spring-projects/spring-framework/issues/32262