These four issues scene investigation and the reasons would you do? Look at how experts are using to quickly locate the cause of Arthas!

lALPGqGoY4ELYOHNAg7NBDg_1080_526.png
Author | [Zhang Qi (Secretary Chu)]

When the line encountered headache, also against the code line by line to see? Really not very stylish, ah Hey ~

1.jpeg

As the saying goes, "Troubleshooting do not worry, Arthas to help you busy." Today to say what her mother no longer have to worry about me troubleshoot Java diagnostics artifact --Arthas!

What is Arthas?

Arthas is an open source online diagnostic tool, a command-line interactive mode, online support web terminal diagnosis, while providing a wealth of Tab Completion features to further facilitate locating and diagnosing problems. This is an open source more than a year GitHub star 2 million, or 99% of R & D brother Ali are using the Java ultimate diagnostic tool! Relatively straightforward to use than downloading, I recommend developers can try to achieve a key remote diagnostic capabilities via Cloud Toolkit IDE plug-in to use Arthas.

Thanks Arthas powerful and feature-rich, let Arthas can do beyond imagination. Here are just to name a few common usage, additional usage scenarios can explore on their own after familiar with Arthas.

  • Is there a global perspective to view the health of the system?
  • Why CPU has increased, and in the end is where taking up CPU?
  • There are multiple threads running deadlock it? There are blocking it?
  • Take a long time to run, it is where it takes longer? How to monitor it?
  • The class from which jar package loaded? Why would report a variety of categories associated Exception?
  • I changed the code to execute Why not? Could it be I did not commit? Branch made a mistake?
  • Get stuck online debug, it only re-released by adding the log it?
  • Is there any way to run real-time status monitoring of the JVM?

Arthas commands, functions in its official documents are detailed below will tell us about the recent several usage scenarios.

Scenario 1: positioning performance bottlenecks pressure measurement

Server requests are usually normal. When the pressure test, dependent service, the database did not reach the bottleneck, but the machine's CPU all rosy, why?

By jstack command, only to see the stack at a certain time, I did not catch the murderer.

thread view the current thread information, see the thread's stack.

thread -n 3 -i 10000 can count 10 seconds busiest three threads, and print their stack, it is easy to find the problem. The final problem identified is relatively simple: print the log location information, including class names, method names and line numbers.

Dynamic code information acquiring method name, line number, usually by new new Throwable () -> Throwable printed stack -> stack taken topmost service code - Get Class> Split string, the information method, the line number, etc. print stack performance loss is relatively large.

2.png

Scene 2: occasional timeout detection

There was a time, always run into the occasional time out several times, but look at the log normal call link Hawkeye are totally ok, no single step or database operations HSF call is particularly slow.

Time dimension of various monitoring statistics of time-consuming, very normal, unable to find the spikes of rt.

Thought might be a problem log, but there is no evidence to support.

trace command to monitor each step of time-consuming, and can be used with conditional expressions, print detailed log of when consuming more than xx ms.

Looking machine, enter the command, such as the back it is quiet. When rt spikes occur again, able to capture the distribution of time-consuming.

3.png

By the results of Arthas get, locate the problem log printing. After synchronization log changed to asynchronous log, the problem is solved.

Scene 3 debug? What if dynamic byte code generation supposed to?

Before the problem I encountered when a json serialized digital output with or without quotes. Debug various time, look at the code, is found by way of ASM generated dynamic class byte code sequence. With this completely abandoned, debug has been unable to locate the problem. At that time another way to avoid this problem.

In turn this question, we can jad command of Arthas, decompile bytecode dynamically generated class, combined with watch commands, locate troubleshoot.

JAD - decompiled source code specifies that loaded the class

4.png

Can also mc (Menory Compiler) , the redefine  the command line hot update the code, welcome to explore.

With these capabilities even if the Almighty? No, no, read on.

Scene 4 to do bad things

In the troubleshooting process, found the log output to the console, the loss of performance is relatively large. Is there any way, without the release of emergency to solve it?

First, find the corresponding class

sc -d ch.qos.logback.core.ConsoleAppender
 
class-info       ch.qos.logback.core.ConsoleAppender
  code-source       /home/admin/.../lib/logback-core-1.2.3.jar
  name             ch.qos.logback.core.ConsoleAppender
  isInterface       false
  isAnnotation     false
  isEnum           false
  isAnonymousClass false
  isArray           false
  isLocalClass     false
  isMemberClass     false
  isPrimitive       false
  isSynthetic       false
  simple-name       ConsoleAppender
  modifier         public
  annotation
  interfaces
  super-class       +-ch.qos.logback.core.OutputStreamAppender
                      +-ch.qos.logback.core.UnsynchronizedAppenderBase
                        +-ch.qos.logback.core.spi.ContextAwareBase
                          +-java.lang.Object
  class-loader     +-com.taobao..LaunchedURLClassLoader@58dad04a
                      +-sun.misc.Launcher$AppClassLoader@18b4aac2
                        +-sun.misc.Launcher$ExtClassLoader@58ceff1
  classLoaderHash   5f205aa
复制代码

Then get attribute information class and find a list of appender

ognl -c 5f205aa '@org.slf4j.LoggerFactory@getLogger("root").aai.appenderList'
复制代码

appender delete the standard output

1ognl -c 5f205aa '@org.slf4j.LoggerFactory@getLogger("root").aai.appenderList.remove(0)'
复制代码

Artifact: Flame map

Troubleshoot performance problems when there is an artifact: the flame by flame chart diagram, it is clear to see that over time, time-consuming statistics for each method.

5.png

Started Arthas

Method 1: Toolkit achieve Arthas a key remote diagnostics via Cloud

Cloud Toolkit is released Ali Free local IDE plug-ins to help developers to more efficiently develop, test, diagnose and deploy applications. Through the plug, the local is possible to apply a key deployment to any server, even cloud (ECS, EDAS, ACK, ACR and applets clouds, etc.); and also built Arthas diagnostic, Dubbo tools, Terminal terminal, a file upload function evaluation and MySQL actuators and other tools. Not only has the mainstream version of IntelliJ IDEA, there are other versions of Eclipse, Pycharm, Maven and so on.

IDEA plug-in is recommended to use the download Cloud Toolkit Arthas: t.tb.cn/2A5CbHWveOX...

Second way: Direct download

Address: github.com/alibaba/art... .

Arthas prize essay started!

6.png

To enable more developers to start to spend Arthas the Java diagnostic artifact, this time we launched the joint JetBrains prize essay activities and talk about all these years that thing between you and Arthas. The first phase of writing activities and March 26 - April 26 held follow-writing activities will last until December 2020.

Content Orientation recommendations:

  • Use Arthas had to troubleshoot a problem
  • Arthas to be interpreted source code
  • Advise on Arthas
  • Any other content related to the Arthas

Step 3 submitted essay

  1. Arthas Arthas directly or via Cloud Tookit;
  2. Your experience will be organized into articles published in the Denver community;
  3. By filling in the form below: alibabadeveloper.mikecrm.com/9khcRrs

You will get a gift

  • Where to submit articles to meet the submission requirements of the students will receive a copy of each child Arthas Most Valuable User (random gift), contains Amoy doll, Arthas stickers, T-shirts Ali, JetBrains surrounding packs;
  • The first phase top3 most popular articles, Lynx get a wizard;
  • Annual top 20 articles, will have access to the keyboard and cherry Coupon JetBrains include other neighboring packs.

You will get the honor

In addition to in-kind bonus, you also get

  • Alibaba Cloud native public numbers and Arthas technology community home page to showcase your articles and the author describes the modules, so that more developers to understand you;
  • To become a contributor Arthas community, involved in the daily operations of the community, and participation Arthas online / offline activities to share as a community instructor.

" Alibaba Cloud native concern micro service, Serverless, container, Service Mesh and other technical fields, focusing cloud native popular technology trends, cloud native large-scale landing practice, most do understand the developer's native cloud technology circles."

Guess you like

Origin juejin.im/post/5e86e71ee51d4546d439684f