High CPU Usage Rate (Linux System)
Last updated: 2019-08-09 18:43:16PDF
High CPU utilization may cause problems such as slow service response speed and server login failure. You can use Cloud Monitor to create an alarm threshold for CPU utilization so that you are promptly notified when CPU utilization exceeds the threshold.
Troubleshooting high CPU utilization involves locating the processes consuming CPU power and analyzing those using a large amount of CPU power. If they are exceptional processes which may be caused by viruses or Trojans, you can terminate the processes or use your security software to check and kill them. If they are business processes, you need to analyze whether high CPU utilization is caused by large number of visits and whether it can be optimized. If they are processes generated by Tencent Cloud components, contact us by submitting a ticket, and we will help you locate and troubleshoot the problem.
The following describes how to locate a process with too high CPU utilization under Linux.
Tool for Locating Programs: top Command
top: A commonly used monitoring tool for Linux systems to get process-level CPU usage in real time. The output information of top command is as follows:
The upper part shows the overall usage of CPU and memory resources:
1st line: The current time of the system, the number of currently logged in users and the system load.
2nd line: Total number of processes, number of running processes, number of dormant processes, number of sleeping processes, and number of zombie processes.
3rd line: Current CPU usage.
4th line: Current memory usage.
5th line: Current swap usage.
The lower part shows the occupancy of resources by process.
PID: Process ID.
USER: Process owner.
PR: Process priority. NI: NICE value. A smaller NICE value means a higher priority.
VIRT: Used VM size, in KB.
RES: Currently used memory size, in KB.
SHR: Used shared memory size, in KB.
S: Process status.
%CPU: The percentage of CPU time used by the process during the update interval.
%MEM: The percentage of memory used by the process during the update interval.
TIME+: CPU time used by the process, accurate to 0.01 sec.
COMMAND: Process name.
Problem Locating and Troubleshooting
Locating processes with high CPU utilization with top
The following describes how to use top to locate processes with high CPU utilization.
Log in to the instance via SSH or VNC
Note: Too high CPU utilization may cause server login failure. At this point, you can try to log in via VNC. For more information on how to log in to an instance via VNC, please see Logging In to Linux Instances.
Enter the top command to view the system load.
Enter "P", and then processes are listed in descending order of CPU utilization, which makes it easy for you to get the processes with high CPU utilization for further analysis.
Analyze the processes with high CPU utilization.
(1) If they are business processes, it is recommended to analyze whether these processes can be optimized or whether the resource configuration of the instance can be enhanced.
(2) If they are exceptional processes, the instance may be poisoned. You can terminate the processes, use your security software to check and kill them, or reinstall the system after data backup.
(3) If they are processes generated by Tencent Cloud components and take up over 20% CPU power, contact us by submitting a ticket, and we will help you locate and troubleshoot the problem.
Common Tencent Cloud components include:
sap00x: Security component process
Barad_agent: Monitoring component process
secu-tcs-agent: Security component process
Terminating processes with top
- Enter "k" and the pid of the process (the first process in the list by default) you want to terminate, and then press Enter.
- After that, a prompt of "Send pid 984 signal [15/sigterm]" appears. Press Enter to confirm.
Handling of the process kswapd0 with high CPU utilization
kswapd0 is the process that swaps pages in virtual memory management in Linux. In addition to managing memory through paging mechanism, Linux also assigns part of disks as virtual memory. When the system is running out of memory, kswapd0 will frequently swap pages, which consumes a large amount of CPU resources, resulting in the process continuously occupying high CPU resources.
After you locate the process kswapd0 with high CPU utilization by using the command top, execute vmstat to view the system's virtual memory. If "si" and "so" are also relatively high, it proves that frequent page swapping operations are performed in the system, which outgrows the physical memory. It is recommended that you upgrade the system's memory.