From 75eef2a67aff0f163a53438b3d9458cf2c8cdf96 Mon Sep 17 00:00:00 2001 From: linyimin0812 Date: Sat, 7 Oct 2023 04:09:13 +0800 Subject: [PATCH] docs: add hotswap docs --- README.md | 31 +++++++++++++++++++++++++++---- README_ZH.md | 28 ++++++++++++++++++++++++---- 2 files changed, 51 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index b56d794..cc9574e 100644 --- a/README.md +++ b/README.md @@ -22,8 +22,10 @@ - [Application Startup](#application-startup) - [Custom extension](#custom-extension) - [🚀Optimization of Spring Startup](#optimization-of-spring-startup-1) - - [Types of Bean for Async](#types-of-bean-for-async) - - [Usage](#usage) + - [Optimization of Prod Env Startup Time](#optimization-of-prod-env-startup-time) + - [Types of Bean for Async](#types-of-bean-for-async) + - [Usage](#usage) + - [Optimization of Daily and Pre Env Startup Time](#optimization-of-daily-and-pre-env-startup-time) - [🔗Reference](#Reference) # Spring Startup Ananlyzer @@ -283,6 +285,8 @@ Once you have installed this project by following the steps in the [Installation ## 🚀Optimization of Spring Startup +### Optimization of Prod Env Startup Time + From the [Application startup data collection](#spring-startup-analysis-report)section, you can obtain the Beans that have long initialization time. Since the Spring startup process is single-threaded, to optimize the application startup time, you can consider making the initialization methods of these time-consuming Beans asynchronous. @@ -293,7 +297,7 @@ NOTE: - **For Beans that are not dependent on other Beans, you can confidently proceed with asynchronous initialization**,You can determine if a Bean is dependent on other Beans by examining the `Root Bean` in [Loading time of Beans](#11-application-startup-data-collection) session - **Careful analysis is required for Beans that are dependent on other Beans. They should not be called by other Beans during the application startup process, as it may lead to issues** -### Types of Bean for Async +#### Types of Bean for Async Supports initialization of beans through @Bean, @PostConstruct, and @ImportResource. demo: [spring-boot-async-bean-demo](https://github.com/linyimin0812/spring-boot-async-bean-demo) @@ -320,7 +324,7 @@ public class TestComponent { ``` -### Usage +#### Usage 1. Import Dependency @@ -353,6 +357,25 @@ View the log in the `$HOME/spring-startup-analyzer/logs/async-init-bean.log` fil async-init-bean, beanName: ${beanName}, async init method: ${initMethodName} ``` +### Optimization of Daily and Pre Env Startup Time + +To optimize the startup time for daily and pre, we can consider hotswap. The project provides a command-line tool to implement hotswap for modified code. + +1. Download `spring-startup-cli` from [release](https://github.com/linyimin0812/spring-startup-analyzer/releases/tag/v3.0.0) +2. Execute the command-line tool in the project's working directory + +```shell +java -jar spring-startup-cli.jar +``` + +3. Configure information using `config` command. + +```shell +config -b -h -p +``` + +4. Execute `reload` command + # 🔗Reference - [arthas](https://github.com/alibaba/arthas) - [jvm-sandbox](https://github.com/alibaba/jvm-sandbox) diff --git a/README_ZH.md b/README_ZH.md index 7b6e7ca..4320ce5 100644 --- a/README_ZH.md +++ b/README_ZH.md @@ -21,8 +21,10 @@ - [应用启动](#应用启动) - [自定义采集能力扩展](#自定义采集能力扩展) - [🚀应用启动时长优化](#应用启动时长优化-1) - - [支持异步化的Bean类型](#支持异步化的bean类型) - - [接入异步Bean优化](#接入异步bean优化) + - [生产环境启动时长优化](#生产环境启动时长优化) + - [支持异步化的Bean类型](#支持异步化的bean类型) + - [接入异步Bean优化](#接入异步bean优化) + - [日常和预发环境启动时长优化](#日常和预发环境启动时长优化) - [🔗参考](#参考) # Spring Startup Ananlyzer @@ -279,6 +281,8 @@ mvn clean package ## 🚀应用启动时长优化 +### 生产环境启动时长优化 + 从[应用启动数据采集](#2-应用启动数据采集)中,可以获取初始化耗时长的Bean,因为Spring启动过程是单线程完成的,为了优化应用的启动时长,可以考虑将这些耗时长的Bean的初始化方法异步化,查看[实现原理](./HOW_IT_WORKS.md#spring-bean异步加载原理)。 需要注意: @@ -288,7 +292,7 @@ mvn clean package - **对于不被依赖的Bean可以放心进行异步化**,可以通过[各个Bean加载耗时](#11-应用启动数据采集)中的`Root Bean`判断Bean是否被其他Bean依赖 - **对于被依赖的Bean需要小心分析,在应用启动过程中不能其他Bean被调用,否则可能会存在问题** -### 支持异步化的Bean类型 +#### 支持异步化的Bean类型 支持@Bean, @PostConstruct及@ImportResource 方式初始化bean,使用demo: [spring-boot-async-bean-demo](https://github.com/linyimin0812/spring-boot-async-bean-demo) @@ -315,7 +319,7 @@ public class TestComponent { ``` -### 接入异步Bean优化 +#### 接入异步Bean优化 1. 添加pom依赖 @@ -348,6 +352,22 @@ spring-startup-analyzer.boost.spring.async.init-bean-thread-pool-max-size=8 async-init-bean, beanName: ${beanName}, async init method: ${initMethodName} ``` +### 日常和预发环境启动时长优化 + +为了优化日常/预发的启动时长,可以考虑热加载。本项目提供了一个命令行工具,实现一个命令完成已修改代码的热加载。 + +1. 在[release](https://github.com/linyimin0812/spring-startup-analyzer/releases/tag/v3.0.0)下载`spring-startup-cli` +2. 在项目的工作目录(HOME)下执行此命令行工具 +```shell +java -jar spring-startup-cli.jar +``` +3. 使用config命令配置相关信息 + +```shell +config -b 部署的分支 -h JVM所在的host -p JVM指定的port +``` +4. 编码完成后执行`reload`命令,即可完成热加载 + # 🔗参考 - [arthas](https://github.com/alibaba/arthas) - [jvm-sandbox](https://github.com/alibaba/jvm-sandbox)