Recommend a useful idea hot deployment plug-in

Table of contents

1. What is hot deployment

2. Why hot deployment is needed

3. Hot deployment products

3.1. JRebel

3.2. IDEA HotSwap

3.3.HotSwapAgent

3.4.Spring Boot DevTools

3.5.FastHotSwapper

4. FastHotSwapper installation and use

reference:


1. What is hot deployment

Hot deployment (Hot Deployment) refers to a technology that can take effect immediately without stopping the entire application after some codes or resources are modified during the running of the application. Hot deployment is often used in development and testing environments, which saves time and improves efficiency, allowing developers to verify the effect of code modifications more quickly. In a production environment, hot deployment can also be used to fix some minor problems or update some functions of the application to avoid the impact of the entire application downtime.

2. Why hot deployment is needed

Our R&D students often encounter the following situations during the daily development and debugging phase:

  1. The properties in the spring bean are missing @Resource or @Autowired annotations
  2. SQL writing error in mybatis sql configuration file
  3. Adding (modifying or deleting) attributes in the entity class causes Fastjson and Jackson to fail to serialize and deserialize normally
  4. The method signature needs to add a parameter or need to add a CheckedException declaration
  5. Add static Logger properties to the class to increase log output

In some of the scenarios listed above, our R&D students must restart the service (such as tomcat) to make the modified code take effect. It may only take about 1 minute for some small systems to restart, but it usually takes about 5 minutes for large systems. If dubbo, mq and other technologies are widely used in the system, it may take longer to restart due to the need to establish a large number of connections during the startup process. According to statistics, R&D students need to restart the service about 10-20 times a day. Frequent service restarts have seriously affected the development and debugging rhythm of R&D students and affected the overall work efficiency.

Hot deployment technology is just to solve this problem. Hot deployment can make most of the code changes made by developers take effect immediately . Quickly test and debug code without restarting the application , helping R&D reduce the number of frequent service restarts and saving fragmentation time.

Avoid application downtime for maintenance due to updates, thereby improving application availability and stability.

3. Hot deployment products

At present, there are not many mature hot deployment products on the market, mainly including JRebel, IDEA HotSwap, HotSwapAgent, and Spring Boot DevTools, all of which can realize hot deployment of code.

3.1. JRebel

A powerful hot-deployment charging product, with IDEA as the user operation entrance, the ecosystem is relatively large, basically covering the hot-deployment of mainstream technical frameworks in the Java ecosystem. Its main disadvantage is that domestic frameworks (fastjson, mybatis-plus, etc.) are basically not supported, and it is a paid product that needs to be cracked.

3.2. IDEA HotSwap

IDEA's built-in hot deployment has relatively weak capabilities and only supports changes in method bodies. Operations that change the class structure, such as adding attributes, adding methods, and modifying the inheritance relationship of classes, are prohibited, and mainstream Java frameworks such as spring and mybatis do not support them. The supported scenarios are very limited, and the functions are relatively single, which is difficult to meet the daily development of R&D students.

3.3.HotSwapAgent

A free and open-source hot-deployment Agent ( github.com/HotswapProj...developed by a foreign team, also does not support domestic frameworks, but because it is completely free and open-source, we can carry out secondary development based on it to support the hot-swap of domestic frameworks Deployment. It is also because it is free and open source. After in-depth research on its source code, it is found that there are some problems in many hot deployment scenarios, including the mybatis proxy interface and the overall support of the spring framework.

The standard JVM only allows modification of the method body of the class at runtime, and does not allow modification of the class structure. The HotSwapAgent team developed a DCEVM patch ( github.com/dcevm/dcevm...this patch allows developers to make any changes to the class during runtime. It is precisely because of the appearance of this patch that the real significance On the hot deployment can be achieved (JRebel is essentially using a similar technical means).

3.4.Spring Boot DevTools

Spring Boot DevTools can only be applied to Spring Boot projects, and it is not incremental hot deployment, but restarts the project through Classloader iterations. For large projects, the performance is unacceptable. To be precise, Spring Boot DevTools is not a hot deployment product in the strict sense.

3.5.FastHotSwapper

Most of the hot deployment products currently on the market are developed by foreign teams and lack support for domestic technical frameworks. FastHotSwapper is just to make up for this gap, providing a powerful, easy-to-use, free hot deployment product that supports domestic frameworks for the majority of R&D students.

FastHotSwapper is designed to improve development efficiency. In short: Modifications take effect immediately without restarting the application throughout the encoding process. Specifically, the software can be upgraded while the application is running without rebooting

FastHotSwapper is an IDEA hot deployment plug-in . Its core (Agent part) is based on the secondary development of HotSwapAgent. It deeply optimizes mainstream technical frameworks such as spring, mybatis, tomcat, and cglib. At the same time, it supports hot deployment for some mainstream domestic frameworks, such as apollo and mybatis. -plus, tk-mybatis, Fastjson, etc. And use IDEA as the user's operation entrance to improve the overall ease of use of hot deployment.

4. FastHotSwapper installation and use

For details, please refer to: plugins.jetbrains.com/plugin/2064…

1) Hot deployment plug-in installation

2) Install dcevm

1. Download the DCEVM patch corresponding to jdk8 from the list below. The jdk version of the patch needs to be one-to-one, otherwise it will cause the jdk to crash.

FastHotSwapper - IntelliJ IDEs Plugin | Marketplace

2. Execute the installation command mac operating system or linux operating system to directly open the terminal and run the following command

cd dcevm所在目录
sudo java -jar dcevm-light-java8u192.jar

Windows operating system, first open cmd as an administrator , and then execute the following command, try not to execute the command on the C drive

cd dcevm所在目录
java -jar dcevm-light-java8u192.jar

After the command is executed, the visual operation interface shown in the figure below will pop up.

The patch needs to be installed on jdk and jre at the same time, click the button in the lower right corner: Install DCEVM as altjvm, and then close the interface.

3) Run java -XXaltjvm=dcevm -version to verify the installation result, if the string " Dynamic Code Evolution " appears, the installation is successful

DCEVM requires that the garbage collector of the application must be SerialGC (the default collector of java8). After installing this patch, the non-SerialGC application will fail to start

4) Turn off IDEA's hot deployment capability , Build, Execution, Deployment > Debug > HotSwap Reload classes after compilation select Never.

The hot deployment that comes with IDEA can only support the change of the method body, and cannot achieve dynamic overloading of frameworks such as spring and mybatis, so the hot deployment function that comes with IDEA is disabled here.

5) Hot deployment start

Debug starts the target application, currently only supports the application started with debug.

Currently, web containers only support tomcat and jetty, while applications deployed in other containers do not support hot deployment.

If the following key information appears, it means that the agent has taken effect. After the service is successfully started, you can experience hot deployment

6) Hot deployment operation

After the coding is completed, you can open the hot deployment panel in the running tab, verify the list of changed files (if the file is missing, you can open the file and use "ctrl+s" to save it), and then click the OK button to start the hot deployment .

You can also use the default shortcut keys (ctrl+alt+9) to start hot deployment with one click

7) Hot deployment is complete

Summary: Generally speaking, it is very easy to use and supports sql hot deployment in XML files, but it is currently found that the new version of UI in the idea of ​​2023.3 is not supported. If you do not use the new version of UI, there should be no problem

reference:

https://juejin.cn/post/7178798474702356540

Guess you like

Origin blog.csdn.net/qq_20957669/article/details/130821947