use of com.alipay.sofa.isle.spring.factory.BeanLoadCostBeanFactory in project sofa-boot by sofastack.
the class ModuleLogOutputStage method logInfoBeanCost.
private void logInfoBeanCost(StringBuilder stringBuilder, List<DeploymentDescriptor> deploys) {
long totalTime = 0;
long realStart = 0;
long realEnd = 0;
stringBuilder.append("\n").append("Spring bean load time cost list").append("(").append(deploys.size()).append(") >>>>>>>");
StringBuilder sb = new StringBuilder();
int size = deploys.size();
for (int i = 0; i < size; ++i) {
String prefix = (i == size - 1) ? SYMBOLIC2 : SYMBOLIC1;
String indexPrefix = (i == size - 1) ? EMPTY_INDEX_PREFIX : INDENT_PREFIX;
DeploymentDescriptor dd = deploys.get(i);
BeanFactory beanFactory = ((ConfigurableApplicationContext) dd.getApplicationContext()).getBeanFactory();
if (realStart == 0 || dd.getStartTime() < realStart) {
realStart = dd.getStartTime();
}
if (realEnd == 0 || (dd.getStartTime() + dd.getElapsedTime()) > realEnd) {
realEnd = dd.getStartTime() + dd.getElapsedTime();
}
totalTime += dd.getElapsedTime();
if (beanFactory instanceof BeanLoadCostBeanFactory) {
sb.append(prefix).append("[Module] ").append(dd.getName()).append(" [").append(dd.getElapsedTime()).append(" ms]\n");
sb.append(((BeanLoadCostBeanFactory) beanFactory).outputBeanStats(indexPrefix));
}
}
stringBuilder.append(" [totalTime = ").append(totalTime).append(" ms, realTime = ").append(realEnd - realStart).append(" ms]\n").append(sb);
}
use of com.alipay.sofa.isle.spring.factory.BeanLoadCostBeanFactory in project sofa-boot by sofastack.
the class AsyncInitBeanDefinitionDecoratorTest method testIsleModule.
@Test
public void testIsleModule() {
String moduleName = "testModule";
BeanLoadCostBeanFactory beanFactory = new BeanLoadCostBeanFactory(10, moduleName);
Assert.assertTrue(AsyncInitBeanDefinitionDecorator.isBeanLoadCostBeanFactory(beanFactory.getClass()));
Assert.assertEquals(moduleName, AsyncInitBeanDefinitionDecorator.getModuleNameFromBeanFactory(beanFactory));
}
use of com.alipay.sofa.isle.spring.factory.BeanLoadCostBeanFactory in project sofa-boot by sofastack.
the class BeanHierarchyTest method test.
@Test
public void test() throws Exception {
ApplicationRuntimeModel application = new ApplicationRuntimeModel();
application.setAppName(this.getClass().getName());
application.setModuleDeploymentValidator(new DefaultModuleDeploymentValidator());
DeploymentDescriptorConfiguration deploymentDescriptorConfiguration = new DeploymentDescriptorConfiguration(Collections.singletonList(SofaBootConstants.MODULE_NAME), Collections.singletonList(SofaBootConstants.REQUIRE_MODULE));
Properties props = new Properties();
props.setProperty(SofaBootConstants.MODULE_NAME, "com.alipay.module");
File moduleDirectory = new File("target/test-classes/module/sofa-module.properties");
DeploymentDescriptor dd = DeploymentBuilder.build(moduleDirectory.toURI().toURL(), props, deploymentDescriptorConfiguration, this.getClass().getClassLoader());
Assert.assertTrue(dd instanceof FileDeploymentDescriptor);
Assert.assertTrue(application.isModuleDeployment(dd));
application.addDeployment(dd);
refreshApplication(application);
BeanFactory beanFactory = ((ConfigurableApplicationContext) dd.getApplicationContext()).getBeanFactory();
for (BeanStat bn : ((BeanLoadCostBeanFactory) beanFactory).getBeanStats()) {
if (bn.getBeanClassName().contains("testService")) {
Assert.assertEquals(3, bn.getChildren().size());
for (BeanStat cbn : bn.getChildren()) {
if (cbn.getChildren().size() > 1) {
Assert.assertEquals(3, cbn.getChildren().size());
}
}
}
}
ApplicationContext applicationContext = application.getResolvedDeployments().get(0).getApplicationContext();
String moduleName = applicationContext.getId();
Assert.assertEquals("com.alipay.module", moduleName);
}
use of com.alipay.sofa.isle.spring.factory.BeanLoadCostBeanFactory in project sofa-boot by alipay.
the class BeanHierarchyTest method test.
@Test
public void test() throws Exception {
ApplicationRuntimeModel application = new ApplicationRuntimeModel();
application.setAppName(this.getClass().getName());
application.setModuleDeploymentValidator(new DefaultModuleDeploymentValidator());
DeploymentDescriptorConfiguration deploymentDescriptorConfiguration = new DeploymentDescriptorConfiguration(Collections.singletonList(SofaBootConstants.MODULE_NAME), Collections.singletonList(SofaBootConstants.REQUIRE_MODULE));
Properties props = new Properties();
props.setProperty(SofaBootConstants.MODULE_NAME, "com.alipay.module");
File moduleDirectory = new File("target/test-classes/module/sofa-module.properties");
DeploymentDescriptor dd = DeploymentBuilder.build(moduleDirectory.toURI().toURL(), props, deploymentDescriptorConfiguration, this.getClass().getClassLoader());
Assert.assertTrue(dd instanceof FileDeploymentDescriptor);
Assert.assertTrue(application.isModuleDeployment(dd));
application.addDeployment(dd);
refreshApplication(application);
BeanFactory beanFactory = ((ConfigurableApplicationContext) dd.getApplicationContext()).getBeanFactory();
for (BeanStat bn : ((BeanLoadCostBeanFactory) beanFactory).getBeanStats()) {
if (bn.getBeanClassName().contains("testService")) {
Assert.assertEquals(3, bn.getChildren().size());
for (BeanStat cbn : bn.getChildren()) {
if (cbn.getChildren().size() > 1) {
Assert.assertEquals(3, cbn.getChildren().size());
}
}
}
}
ApplicationContext applicationContext = application.getResolvedDeployments().get(0).getApplicationContext();
String moduleName = applicationContext.getId();
Assert.assertEquals("com.alipay.module", moduleName);
}
use of com.alipay.sofa.isle.spring.factory.BeanLoadCostBeanFactory in project sofa-boot by alipay.
the class StartupSpringContextInstallStage method doRefreshSpringContext.
@Override
protected void doRefreshSpringContext(DeploymentDescriptor deployment, ApplicationRuntimeModel application) {
ModuleStat moduleStat = new ModuleStat();
moduleStat.setName(deployment.getModuleName());
moduleStat.setStartTime(System.currentTimeMillis());
super.doRefreshSpringContext(deployment, application);
moduleStat.setEndTime(System.currentTimeMillis());
moduleStat.setCost(moduleStat.getEndTime() - moduleStat.getStartTime());
moduleStat.setThreadName(Thread.currentThread().getName());
ConfigurableApplicationContext ctx = (ConfigurableApplicationContext) deployment.getApplicationContext();
ConfigurableListableBeanFactory beanFactory = ctx.getBeanFactory();
if (beanFactory instanceof BeanLoadCostBeanFactory) {
moduleStat.setChildren(((BeanLoadCostBeanFactory) beanFactory).getBeanStats());
}
contextRefreshStageStat.addChild(moduleStat);
}
Aggregations