Contents
- First, find out what the 100 percent displayed means
- Watch multiple samples instead of a single image
- Distinguish between user computation, kernel, and waiting
- A single process can have many threads or short-lived children
- Compare short regular peaks with timers and cron
- Pidstat and related metrics will help refine the picture
- Quotas and limits can create a queue without using up the entire host
- Deduce the intervention from the confirmed cause
- Frequently asked questions
First, find out what the 100 percent displayed means
The CPU number is meaningless without context. The tool may show a percentage of the entire VM or a value converted to one logical CPU. With two vCPUs, one fully loaded thread may represent 100 percent in the process list and approximately 50 percent of the total capacity. This is not a contradiction, but a different denominator. For a multithreaded process, the process value may exceed 100 percent in the corresponding mode.
Write down where you saw the value, what the interval is, and how many logical CPUs the system is using. The hypervisor panel, the container, and the top inside the VM may not all be accounting for the same things. The available quota is also important: a container may see many CPUs, but only be allocated a fraction of their time. So the number of cores alone may not correspond to the usable capacity of the application.
date -Is
nproc
lscpu
uptime
topA one-time spike is not automatically a problem. Check to see if responses have become longer, queued, or services have started to fail. A fully loaded batch may work fine, while low CPU with long disk waits can mean serious slowdowns. The goal is not to reduce the percentage at all costs, but to find a relationship between the load and the behavior of the service.
Watch multiple samples instead of a single image
If the problem persists, use top with a short but reasonable interval. The first output may not represent the same time period as subsequent refreshes. Watch for multiple consecutive samples and sort the list by CPU. Note the exact times, PIDs, and process names for later comparison. A long, unending log of everything is not needed for initial orientation.
top -b -d 1 -n 10 -o %CPU
ps -eo pid,ppid,user,comm,pcpu,pmem,etime --sort=-pcpu | head -20The %CPU value in a regular ps represents the ratio of the current CPU time to the lifetime of the process, not the same instantaneous interval as the next top sample. Therefore, a long-running process with a recent peak may have a low average, while a newly created process may appear to be significantly higher. Compare metrics by their definition, not just by the common percentage symbol.
If you need a full command line, use it sparingly. Some programs incorrectly include tokens or passwords in their arguments; do not copy such a listing into a public report. The name, PID, parent, and account are usually sufficient for initial identification. Do not terminate a foreign process simply because you have not seen its name before.
Distinguish between user computation, kernel, and waiting
The top summary line breaks down the time by type of work. Us denotes normal user work, sy kernel time, and ni user work of processes with a nice priority. So a high ni still means actual CPU usage, not an idle system. Changing the priority can help more important tasks, but it does not eliminate the cost of the computation itself.
- Id: idle time; its decrease helps assess the capacity used.
- Wa: accounting view of waiting for I/O, not proof that a particular process needs a faster CPU.
- St: time taken from the virtual CPU by the hypervisor; may indicate host sharing.
- Hi and si: work related to hardware and software interrupts.
These values are a guide, not a standalone diagnosis. High sy may be related to frequent system calls or network, but you need to find the specific load. I/O wait has accounting limitations, and a low value does not rule out a slow application waiting for a remote service. Additionally, a high load average is not a percentage of CPU and also includes some tasks waiting non-stop.
A single process can have many threads or short-lived children
An application can divide work among threads, worker processes, and helpers. The top-most python3 or php may not be self-explanatory about who is running it. Find out the parent and the service involved. For multiple threads, it can be useful to look at the individual TIDs; one overloaded worker thread may be hidden under the overall average of a larger process.
# PID nahraďte skutečným číslem z měření:
ps -L -p PID -o pid,tid,psr,pcpu,stat,comm
top -H -p PID
# Při použití systemd:
systemctl status PID --no-pagerThe last command can help assign the process to a systemd unit. For a container or user service, the view may be different. Verify that the PID still exists and is not reused by another process. The startup and reboot times are also important when analyzing an old record. A number alone without context is not enough to safely send a signal.
You may miss frequently recurring short processes between snapshots. In that case, focus on the common parent, unit, or cgroup and its aggregate CPU time. Don't expect a one-minute refresh of the graph to accurately identify a program that runs for two seconds and then quits.
Compare short regular peaks with timers and cron
A peak every minute could be a synchronization, a statistics calculation, or an integrity check. A peak every few hours could be a backup. View the schedule and compare the times to the actual progress, not just the declared interval. Some timers have a tolerance or random delay, and the task can be triggered even when a file changes.
systemctl list-timers --all --no-pager
sudo journalctl -u NAZEV.service --since "-30 min" --no-pager
systemctl show NAZEV.service -p CPUUsageNSec \
-p ExecMainStartTimestamp -p ExecMainExitTimestampReplace NAME with the unit you found. If appropriate accounting is enabled, the journal may report the CPU time consumed for the completed run. Three CPU seconds is not the same as three seconds of total duration or three percent. For a single-threaded job, it may indicate a short period of intense load, even if the average over the entire minute is low.
Zero files transferred does not mean zero sync work. The task can still traverse names, check metadata, and prepare the manifest. Similarly, a hash cache can prevent repeated reads of large content, but it does not eliminate all tree traversals. Judge the effectiveness of the optimization by the specific work removed and the actual measurement, not by the expectation of an absolutely flat graph.
Pidstat and related metrics will help refine the picture
If sysstat is available on the system, use pidstat for a limited series of interval samples. Installing a new diagnostic package is an administrator's decision; there is no need to change the production system for a first look. With an existing tool, select relevant processes or a short period to keep the output readable.
# Pouze pokud je sysstat nainstalovaný:
pidstat -u -r -d -p ALL 1 10
# Další čtecí souvislosti:
vmstat 1 10
free -hDistinguish between CPU time, memory, and I/O for a specific task. Higher CPU may be due to heavy computation, encryption, or compression, for example, but without a profile, you can't determine the specific function of the program. Running a profiler, strace, or detailed network log can have overhead and capture sensitive data. Use them sparingly only after basic measurements have identified the right process and question.
When comparing before and after, keep the load, number of workers, and time window similar. Lower CPU with fewer requests is not in itself proof of optimization. Also record responses and error rates: reducing the number of workers can calm the graph while lengthening the user queue.
Quotas and limits can create a queue without using up the entire host
A service may have a limit in systemd CPUQuota or a cgroup container. The available performance may then not match what nproc shows. If the quota is exhausted, the task waits for another allocation, even if other host processors are idle. Check the effective unit settings and parent group hierarchy, as the limits may be shared.
systemctl show NAZEV.service -p CPUQuotaPerSecUSec \
-p CPUWeight -p AllowedCPUs -p ControlGroupCPUQuota=100% in systemd roughly corresponds to the time of one CPU, not automatically the full capacity of each multi-core machine. CPUWeight, on the other hand, specifies the relative weight in resource contention and is not the same kind of limit. Increasing the quota without knowing the priorities of other services may shift the problem to another application.
For a virtual server, also compare the host conditions and possible steal. Adding vCPU will only help if the application can use the additional capacity and the problem is truly CPU-related. A single-threaded bottleneck or database wait may not be improved by simply increasing the number of cores.
Deduce the intervention from the confirmed cause
First, determine whether it is an expected batch job, an error loop, a request overload, or limited capacity. Possible solutions include rescheduling, eliminating repetitive work, caching, fixing a specific error, or adequate capacity. Terminating the process is a specific operational intervention with an assessment of the data in progress and the recovery method.
- You have a process or unit and a time interval corresponding to the peak.
- It is clear whether the percentages mean the core, the entire VM, or a limited cgroup.
- You distinguished CPU from I/O wait and from host limitation.
- You measure the effect of the change along with the response and error rate.
- You do not terminate or disable integrity checks without knowing their purpose.
In CH-J Tools, the System Monitor will help you with orientation in the overall status and the terminal with assignment of a specific task. However, short peaks require an appropriate measurement interval and correlation with services. Also, the name of a virtual machine, for example, nginx, does not mean that all its CPU is consumed by the nginx process. First, determine the real culprit.
Frequently asked questions
Why does the process show 100% but the VM only shows 50%?
On two vCPUs, the process value calculated against one CPU can be half the total capacity. Verify the mode and definition of both tools.
Is a high load average the same as a high CPU?
No. Linux includes some non-interruptible waiting tasks in the load average. You also need to look at CPU and I/O.
Can I trust a single ps listing for a short tip?
Not enough. %CPU in ps is usually an average over the life of a process and you can miss a short process that has already ended.
Will adding more vCPUs help?
Only if the bottleneck is usable processor capacity. A single overloaded thread, quota, or waiting for another service requires further consideration.
Detailed documentation
procps-ng: top and CPU accounting →
procps-ng: ps and the definition of %CPU →
sysstat: interval statistics pidstat →