Skip to content

Commit

Permalink
docs: add hotswap docs
Browse files Browse the repository at this point in the history
  • Loading branch information
linyimin0812 committed Oct 6, 2023
1 parent 5cdec1c commit 75eef2a
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 8 deletions.
31 changes: 27 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.


Expand All @@ -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)

Expand All @@ -320,7 +324,7 @@ public class TestComponent {
```


### Usage
#### Usage

1. Import Dependency

Expand Down Expand Up @@ -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 <deployed branch> -h <host of JVM> -p <port of JVM>
```

4. Execute `reload` command

# 🔗Reference
- [arthas](https://github.com/alibaba/arthas)
- [jvm-sandbox](https://github.com/alibaba/jvm-sandbox)
Expand Down
28 changes: 24 additions & 4 deletions README_ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
- [应用启动](#应用启动)
- [自定义采集能力扩展](#自定义采集能力扩展)
- [🚀应用启动时长优化](#应用启动时长优化-1)
- [支持异步化的Bean类型](#支持异步化的bean类型)
- [接入异步Bean优化](#接入异步bean优化)
- [生产环境启动时长优化](#生产环境启动时长优化)
- [支持异步化的Bean类型](#支持异步化的bean类型)
- [接入异步Bean优化](#接入异步bean优化)
- [日常和预发环境启动时长优化](#日常和预发环境启动时长优化)
- [🔗参考](#参考)

# Spring Startup Ananlyzer
Expand Down Expand Up @@ -279,6 +281,8 @@ mvn clean package

## 🚀应用启动时长优化

### 生产环境启动时长优化

[应用启动数据采集](#2-应用启动数据采集)中,可以获取初始化耗时长的Bean,因为Spring启动过程是单线程完成的,为了优化应用的启动时长,可以考虑将这些耗时长的Bean的初始化方法异步化,查看[实现原理](./HOW_IT_WORKS.md#spring-bean异步加载原理)

需要注意:
Expand All @@ -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)

Expand All @@ -315,7 +319,7 @@ public class TestComponent {
```


### 接入异步Bean优化
#### 接入异步Bean优化

1. 添加pom依赖

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 75eef2a

Please sign in to comment.