简体   繁体   English

慢弹簧上下文初始化

[英]slow spring context initialization

Our context init jumped from 60 sec to about 15 minutes. 我们的上下文初始化从60秒跃升到大约15分钟。 In both the slow and fast cases, it does eventually start up successfully. 在慢速和快速情况下,它最终都成功启动。 There are no fatal errors either way. 两种方式都没有致命错误。 Are there particular logging settings or even suggested classes to set breakpoints (or add breakpoint logging)? 是否有用于设置断点(或添加断点日志)的特定日志记录设置甚至建议的类?

I've already found the revision where that behavior started, but it is not clear what's causing it to take so much longer. 我已经找到了该行为的开始版本,但尚不清楚是什么原因导致它花费了更长的时间。 I've set breakpoints throughout DefaultListableBeanFactory among others. 我已经在DefaultListableBeanFactory中设置了断点。 It's a big application, so at points the call stack is hundreds deep in getting and creating beans, but comparing that against the prior revision (which finishes quickly) shows a similar nature. 这是一个很大的应用程序,因此,在获取和创建bean时,调用堆栈有数百个深处,但是将其与先前的版本(快速完成)进行比较则显示出类似的性质。 Nothing appears out of the ordinary, between the slow and fast revisions. 在慢速修订版和快速修订版之间,没有任何异常。

I've paused execution at random points through "the slow part" and the stack trace appears reasonable, instantiating new beans as needed, setting properties where possible (which expectably leads to more recursive doCreateBean calls, etc...). 我已经通过“慢速部分”在随机点处暂停了执行,并且堆栈跟踪看起来很合理,可以根据需要实例化新bean,并在可能的情况下设置属性(这可能会导致递归的doCreateBean调用,等等。)。

I haven't yet bothered to set up a profiler, but doubt that it will be useful. 我还没有设置一个探查器的麻烦,但是怀疑它是否有用。 The code that the slow revision spends all its time in (bean factory, context init), is of course the same code that the fast revision spends most its time in too. 慢速修订版将所有时间都花在上面的代码(bean工厂,上下文初始化),当然也与快速修订版将大部分时间都花在上面的代码相同。

You might want to check a verbose GC log. 您可能要检查详细的GC日志。 It could be that it's creating a lot of objects somehow and you would see either 1) the heap growing constantly indicating 'extra' beans or 2) a lot of nursery GC's indicating a lot of object creation but not much sticking around (by being added to the context). 可能是它以某种方式创建了许多对象,您可能会看到1)堆不断增长,表明有“多余的”豆子;或者2)大量的苗圃GC,表明有很多对象被创建,但粘连不多(通过添加)到上下文)。

For #1, a tool like Eclipse MAT will help you analyze a heap dump for the objects that are taking the most memory. 对于#1,类似Eclipse MAT的工具将帮助您分析占用最大内存的对象的堆转储。

For #2, a profiler would still help. 对于#2,分析器仍然会有所帮助。 Look at number of calls made, not time spent. 查看拨打的电话数量,而不是花费的时间。 You would want to find constructors or other create / init methods that are being called a huge amount of times. 您可能想要查找被调用很多次的构造函数或其他create / init方法。 From there you can trace back up to find the offending bean. 从那里可以追溯到找到有问题的bean。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM