Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to restart hot updates with Arthas

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

How to restart hot updates with Arthas, in view of this problem, this article introduces the corresponding analysis and solutions in detail, hoping to help more partners who want to solve this problem to find a more simple and easy way.

I. Preface

The scenario of hot update code

1) when there is a problem with the online server, sometimes the existing means are not enough to find the problem, and it may be necessary to print additional logs or add some debugging code. If we change the code and redeploy, it will destroy the problem site. You can add debugging code by means of hot deployment

2) when an emergency bug occurs online, the problem is found through the Review code. After modification, the process of packaging and deployment may take a long time, and the problem can be solved in time through the hot deployment code.

II. The use of Arthas

Using the Java diagnostic tool-Arthas, he can attach to our Java server process, view server status, jvm status and other parameters, and can also perform hot updates.

1. Download and start Arthas

Wget https://alibaba.github.io/arthas/arthas-boot.jarjava-jar arthas-boot.jar2, after startup, all java processes on the current machine will be displayed. Select the processes we need to monitor / modify, and enter the serial number to enter.

3. Some common commands. If there is a problem online, you can check whether the indicators are abnormal by using the following command.

Real-time data panel of dashboard-- current system thread-- view thread stack information of current JVM jvm-- view information of current JVM sysprop-- view and modify system properties of JVM sysenv-- view environment variable getstatic-- of JVM view static properties of class

1) print the top five threads that consume the most CPU, and you can find the code location with too high CPU in time.

Thread-n 52) View the call stack of a function

Stack 3) check which subcall of a function is the slowest and the longest call will be shown in red, which makes it easy to find out the most time-consuming operation in a function.

Trace 4) monitors the call statistics of a function, including the total number of calls, average running time, success rate, etc.

Monitor 4. Enter exit to exit the current connection, but the Arthas attached to the server process is still running. If you exit completely, you can enter shutdown.

III. Hot renewal

1. First find the full package name of the code we need to update, and decompile the running code online through the jad command

Jad-- source-only > 2. After we get the java code, we modify the code as needed. It should be noted that the practical principle of the hot update code here is to call the redefineClasses method of the Java basic class java.lang.instrument.Instrumentation, which can replace the existing class file by modifying the bytecode. There are many restrictions:

1) for example, field/method cannot be added or deleted.

2) A function that does not exit cannot take effect. For example, a where (true) loop inside a function will never end, and the modified code will never take effect.

We can add some code to the function, such as adding log printing, etc.

3. After modifying the code, we need to find the class loader corresponding to this class, and then load the class. The following command will return the object address of the class loader.

Sc-d | grep classLoaderHash4, compiling Java files into Class files through in-memory compilation

Mc-c 5. Finally, we hot update the class file with the command

This is the answer to redefine's question on how to restart hot updates with Arthas. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report