% Correct cognition of iowait and CPU usage, % iowaitcpu Cognition
Resources
- % IOWAIT (% WIO)
- Linux cpu usage and LOAD
- Linux Performance Observability Tools
- How Linux CPU Usage Time and Percentage is calculated
- Linux Process status
Man (on RHEL 7)
# man mpstat%usr Show the percentage of CPU utilization that occurred while executing at the user level (application).%nice Show the percentage of CPU utilization that occurred while executing at the user level with nice priority.%sys Show the percentage of CPU utilization that occurred while executing at the system level (kernel).Note that this does not include time spent servicing hardware and software interrupts.
%iowait Show the percentage of time that the CPU or CPUs were idle during which the system had an outstanding disk I/O request.%irq Show the percentage of time spent by the CPU or CPUs to service hardware interrupts.%soft Show the percentage of time spent by the CPU or CPUs to service software interrupts.%steal Show the percentage of time spent in involuntary wait by the virtual CPU or CPUs while the hypervisor was servicing another virtual processor.%guest Show the percentage of time spent by the CPU or CPUs to run a virtual processor.%gnice Show the percentage of time spent by the CPU or CPUs to run a niced guest.%idle Show the percentage of time that the CPU or CPUs were idle and the system did not have an outstanding disk I/O request.# man topus, user : time running un-niced user processessy, system : time running kernel processesni, nice : time running niced user processesid, idle : time spent in the kernel idle handlerwa, IO-wait : time waiting for I/O completionhi : time spent servicing hardware interruptssi : time spent servicing software interruptsst : time stolen from this vm by the hypervisor
TIPS
- CPU Usage Time and Percentage
Refer to the mpstat manual, % usr + % nice + % sys + % iwoait + % irq + % soft + % steal + % guest + % gnice + % idle = 100% % steal is generally visible in virtual machines value, for example, CPU overcommitment is very serious, while % guest and % nice are generally very low,
Therefore, you can also obtain it based on/proc/stat or top, user + nice + system + idle + iowait + irq + softirq + steal = 100To calculate Linux CPU usage time subtract the idle CPU time from the total CPU time as follows: total CPU time since boot = user + nice + system + idle + iowait + irq + softirq + stealTotal CPU Idle time since boot = idle + iowaitTotal CPU usage time since boot = (Total CPU time since boot) -(Total CPU Idle time since boot) Total CPU percentage = (Total CPU usage time since boot)/(Total CPU time since boot X 100)
Running status (TASK_RUNNING ):
It is a combination of running and ready States, indicating that the process is running or ready to run. in Linux, The TASK_RUNNING macro indicates that this state can interrupt the sleep state (light sleep) (TASK_INTERRUPTIBLE ):
The process is sleeping (congested). Wait for the resource to arrive to wake up. You can also wake up by another process signal or clock interruption to enter the running queue. In Linux, TASK_INTERRUPTIBLE macro is used to indicate this status. Uninterrupted sleep (deep sleep) (TASK_UNINTERRUPTIBLE ):
It is basically similar to light sleep, but one thing is that it cannot be awakened by signals or clock interruptions from other processes. In Linux, TASK_UNINTERRUPTIBLE macro is used to indicate this state. Paused (TASK_STOPPED ):
The process is paused for processing. If the process being debugged is in this status, Linux uses the TASK_STOPPED macro to indicate this status. Dead state (TASK_ZOMBIE ):
The process has ended but has not released the PCB. in Linux, use the TASK_ZOMBIE macro to indicate this status.
- % Correct understanding of iowait
% Iowait indicates that a few percent of the time in a sampling period belongs to the following situations:CPU idle and unfinished I/O Request.
There are two common misunderstandings about % iowait:
First, I mistakenly thought that % iowait indicates the time when the CPU cannot work,
Second, I/O bottlenecks are mistakenly indicated by % iowait.
First, % increasing iowait does not prove that the number of processes waiting for I/O has increased, nor does it prove that the total time waiting for I/O has increased.
For example, if I/O occurs during the CPU busy period, % iowait will not change regardless of the number of I/O operations. When the CPU is busy, some IO falls into the idle CPU period, resulting in % iowait increase.
For example, if I/O concurrency is low, % iowait is high. If I/O concurrency is high, % iowait may be relatively low.
It can be seen that % iowait is a very vague indicator. If % iowait is increased, check whether the I/O volume increases significantly, and whether avserv/avwait/avque indicators increase significantly, does the application feel slower? If not, there is no worries.
- To view CPU usage, we recommend the following Linux commands:
# top# sar -u 1 5# vmstat -n 1 5# mpstat -P ALL 1 5
- To view the Load value, we recommend the following Linux Command:
# top# uptime# sar -q 1 5