The author | Zhou Zhongtai alibaba moved a brick of the tao is a division of work

Arthas official community is holding an essay call for prizesClick on the submit】

Arthas Hot Swap introduction

The introduction

Hot deployment is a powerful tool to help developers improve efficiency. If your development language is Java and your development environment is remote server, the debug port of the remote server is limited, you may not be able to implement hot deployment through debug HotSwap. The IntelliJ IDEA plugin introduced in this article can help you achieve hot deployment on a remote server, and it is easy and quick to operate.

Arthas Hot Swap is based on Arthas Re-define. Remote Hot deployment requires no configuration, no debug port, and just a few simple actions. GitHub address: github.com/xxxtai/arth…

Method of use

  1. Install the IntelliJ IDEA plugin Arthas Hot Swap, and then download the installation package from gitHub Releases.
  2. In hot deployment, class files are used. Therefore, you need to compile related projects with “MVN compile”. Later, you can compile a single file with IDEA Recompile to save compilation time.
  3. Select the Java source file or class file for Hot deployment, right-click the class name or method name, and choose Swap this Class in Arthas Hot Swap. After successful execution, the commands required for Hot deployment will be copied to the paste board.
  4. Log in to the remote server, paste the hot deployment command, and run it. The hot deployment is complete, and the machine is running the latest class. If the hot deployment command fails for the first time, try again.

Step 1: Select the Arthas Hot Swap option

Step 2: Log in to the remote server and paste the command and execute it

Step 3: The hot deployment is successful

Restrictions on hot deployment

Re-define is a hot deployment based on Arthas and Re-define is a hot deployment based on the Instrumentation API, so it has the same limitations as IDEA debug HotSwap. The restrictions are as follows: You cannot change the name of a class or method, modify the name of a class attribute, add a class attribute, or add a non-static method. Because the plug-in is currently unable to obtain the class file of the inner class, modification of the inner class is not supported.

Arthas Hot Swap works

Arthas is Alibaba’s open source Java code diagnostic tool. Arthas’s Re-define command is a hot deployment based on the Instrumentation API, so it has the same limitations as HotSwap’s hot deployment. Arthas’s Define command is a redefineClasses method wrapped around the Instrumentation API, so we can use our imagination to implement hot deployment.

The Arthas documentation recommends using a series of commands like JAD/MC/Re-define for class remote hot replacement. The process goes something like this: Re-define hot replace class = define hot replace class = define hot replace class There are two problems with this approach: one is that it is too troublesome, and the other is that MC compilation is likely to fail. If only we could do that, locally modify the code, upload the class file to a remote server, and use re-define to hot replace the class. So the documentation recommends converting the class binary to Base64 encoding, copying and pasting it to a remote server, converting the Base64 encoding to a class file, and finally using Re-define for hot replacement. We might as well redeploy. So re-define is a weak order.

The biggest problem with Arthas’s official recommended hot replacement method is that uploading a class file to a remote server for hot replacement is too cumbersome, so why not hand over the cumbersome and fixed process to a machine? This is why the Arthas Hot Swap plugin recommended in this article is necessary to improve the efficiency of Arthas Hot Swap. Hot Swap of a class file with a few simple actions can solve 80% of the Hot deployment requirements during development. The other 20 percent can just be redeployed.

Arthas Hot Swap execution process

  1. The default path is /target/classes. You can also select a class file directly.
  2. Aes-128 encryption class file, base64 encoding output;
  3. Upload the encrypted class file to the OSS and return the OSS access address.
  4. Render scripts that need to be executed for hot deployment. The rendered scripts are also uploaded to oss and the OSS access address is returned.
  5. Assemble hot deployment commands and automatically copy them to the paste board.

Remote server hot deployment process

  1. Log in to the remote server, paste the hot deployment command, and run the command.
  2. Download the hot deployment script and execute the hot deployment script.
  3. Create a workspace;
  4. Check whether OpenSSL is installed. If no, install it.
  5. Download the AES-128 encrypted class file;
  6. Use OpenSSL ENC to decrypt the class binary file.
  7. Install arthas as a script;
  8. Create a pipeline to communicate with ArthAS and start ArthAS;
  9. Arthas selects the Java process, the first by default;
  10. Arthas executes re-define hotreplace class file
  11. Print the result of hot replacement.

Arthas’s essay campaign is in full swing

Arthas is officially holding an essay call if you have:

  • Problems identified using Arthas
  • Source code interpretation of Arthas
  • Advise Arthas
  • No limit, other Arthas related content

Welcome to participate in the essay activity, there are prizes to win oh ~ click to submit

“Alibaba Cloud originator focuses on micro-service, Serverless, container, Service Mesh and other technical fields, focuses on the trend of cloud native popular technology, large-scale implementation of cloud native practice, and becomes the public account that most understands cloud native developers.”