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

What happens before the Java process is transferred

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article focuses on "what happens before the Java process is transferred". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn what happens before the Java process is transferred.

1. Current network connection of the system

Ss-antp > $DUMP_DIR/ss.dump 2 > & 1

This command outputs all network connections to the system to a ss.dump file. The reason for using the ss command instead of netstat is that netstat executes very slowly when there are a lot of network connections.

Follow-up processing, by looking at a variety of network connection status comb, to troubleshoot TIME_WAIT or CLOSE_WAIT, or other high connection problems, is very useful.

2. Network status statistics

Netstat-s > $DUMP_DIR/netstat-s.dump 2 > & 1

Output the network statistics status to the netstat-s.dump file. It can output statistics according to each protocol, which plays a very important role in grasping the state of the whole network at that time.

Sar- n DEV 1 2 > $DUMP_DIR/sar-traffic.dump 2 > & 1

The above command uses sar to output the current network traffic. Running full of network cards often occurs on some very high-speed modules, such as redis and kafka.

3. Process resources

Lsof- p $PID > $DUMP_DIR/lsof-$PID.dump

It's a very powerful order. You can see which files are opened by the process, which is an artifact that allows you to view the usage of the entire resource in the dimension of the process. This command in the case of a lot of resources, the output is a little slow, wait patiently.

4. CPU resources

Mpstat > $DUMP_DIR/mpstat.dump 2 > & 1 vmstat 1 3 > $DUMP_DIR/vmstat.dump 2 > & 1 sar- p ALL > $DUMP_DIR/sar-cpu.dump 2 > & 1 uptime > $DUMP_DIR/uptime.dump 2 > & 1

These orders, we are

Linux's the rest of his Life on a Desert Island (II) CPU

This article has been introduced in more detail. It mainly outputs the CPU and load of the current system, which is easy to be checked afterwards.

There is a lot of overlap in the functions of these commands, and users should pay attention to discrimination.

5. Icano resources

Iostat-x > $DUMP_DIR/iostat.dump 2 > & 1

In general, for computing-based service nodes, the Icano resources will be relatively normal. But sometimes there are problems, such as too much log output, or disk problems. This command outputs basic performance information for each disk and is used to troubleshoot Icano problems.

6. Memory problem

Free-h > $DUMP_DIR/free.dump 2 > & 1

The memory problem is more complex, if you are interested, you can take a look at the summary of xjjdog out-of-heap memory troubleshooting. The general problem that occurs is the JVM memory overflow, which is explained in the process section.

The free command provides a general overview of the memory of the operating system and is a very important point in troubleshooting.

7. Other overall situation

Ps-ef > $DUMP_DIR/ps.dump 2 > & 1 dmesg > $DUMP_DIR/dmesg.dump 2 > & 1 sysctl-a > $DUMP_DIR/sysctl.dump 2 > & 1

In other xjjdog articles, we talked about dmesg more than once. Dmesg is the last clue left by many quietly dead services.

Of course, ps as a command with the highest frequency of execution, its output information at that time must have some reference value.

Because of the configuration parameters of the kernel, it will have a great impact on the system. So we also sent out a copy.

Snapshot of the process, last words

1 、 jinfo

${JDK_BIN} jinfo $PID > $DUMP_DIR/jinfo.dump 2 > & 1

This command outputs basic process information for java. Including environment variables and parameter configuration.

2. Gc information

${JDK_BIN} jstat-gcutil $PID > $DUMP_DIR/jstat-gcutil.dump 2 > & 1 ${JDK_BIN} jstat-gccapacity $PID > $DUMP_DIR/jstat-gccapacity.dump 2 > & 1

Jstat will output the current gc information. In general, you can generally see a clue, if not, will be analyzed with the help of jmap.

3. Heap information

${JDK_BIN} jmap $PID > $DUMP_DIR/jmap.dump 2 > & 1 ${JDK_BIN} jmap-heap $PID > $DUMP_DIR/jmap-heap.dump 2 > & 1 ${JDK_BIN} jmap-histo $PID > $DUMP_DIR/jmap-histo.dump 2 > & 1 ${JDK_BIN} jmap- dump:format=b,file=$DUMP_DIR/heap.bin $PID > / dev/null 2 > & 1

Jmap will get the dump information for the current java process. As shown above, the fourth command is actually the most useful, but the first three allow you to make a preliminary overview of the system.

Because the files produced by the fourth command are generally very large. Also, you need to download it and import a tool like MAT for in-depth analysis to get the results.

4. Execution stack

${JDK_BIN} jstack $PID > $DUMP_DIR/jstack.dump 2 > & 1

Jstack will get the execution stack at that time. We usually take the value many times, and we can take it once here. This information is very useful to restore the thread condition in your java process.

Top- Hp $PID-b-n 1-c > $DUMP_DIR/top-$PID.dump 2 > & 1

To get more detailed information, we use the top command to get cpu information for all threads in the process. In this way, we can see where the resources are being spent.

5. Senior substitute

Kill-3$ PID

Sometimes, jstack doesn't work. There are many reasons, for example, that the java process is almost unresponsive. We will try to send a kill-3 signal to the process. This signal is enjoyed by the java process and will print jstack trace information to the log file. It's a backup plan for jstack.

Gcore-o $DUMP_DIR/core $PID

There is also a replacement for the problem where jmap cannot be executed, and that is gcore in the GDB component. A core file will be generated. We can use the following command to generate dump

${JDK_BIN} jhsdb jmap-exe ${JDK} java-- core $DUMP_DIR/core-- binaryheap

Instantaneous state and historical state

Xjjdog creates two nouns here. The instantaneous state refers to the snapshot type elements that occurred at that time, while the historical state refers to the resource change map with fixed monitoring items captured according to frequency.

There is a lot of information above, such as CPU, system memory, etc., the value of the instantaneous state is not as intuitive as the historical state, because it also has a baseline problem. So it would be much better if there were tools such as monitoring systems.

But for lsof,heap and so on, this kind of mixed information without the concept of time series can not enter the monitoring system and produce useful value, so it can only be analyzed by instantaneous state. In this case, the value of the instantaneous is greater.

At this point, I believe you have a deeper understanding of "what happens before the Java process transfer". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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

Development

Wechat

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

12
Report