CPU usage is divided into
- User-configured CPU usage: The percentage of time that the application code was executed in total CPU time
- System-State CPU Usage: Percentage of total CPU time that the application performed operating system calls
System-State CPU usage means that there is a competition for shared resources or that there is a lot of interaction between IO devices.
Goal: Ideal applications achieve maximum performance and scalability with system-State CPU utilization of 0%, providing application performance and scalability one goal is to minimize system-state CPU usage
For compute-intensive applications
- Monitor user Configuration and System State CPU usage
- Monitor per-clock instruction book IPC or CPI per instruction clock cycle (important for compute-intensive, system-brought tools cannot be monitored)
Stagnation: The CPU waits for data in memory, and the operating system tool still reports that the CPU is busy, which occurs when the operation data used by the instruction is not in the register or in the cache.
Goal: Reduce latency or improve CPU cache usage, thus reducing the CPU's wasted clock cycles while waiting for memory data
Observe the CPU Usage tool
Vmstat: Can only view overall CPU usage
- US: Percentage of user Process execution time. when the value of us is higher, it means that the user process consumes more CPU time, but if it is used over a long period of 50%, then we should consider optimizing the program algorithm or accelerating
- Sy: Percentage of kernel system process execution time. when the value of SY is high, it indicates that the system kernel consumes more CPU resources, this is not a benign performance, we should check the cause
- The percentage of Wa:io waiting time. when the value of WA is high, the IO Wait is serious, which may be caused by random access to the disk, or it may be a bottleneck
- ID: Percentage of idle time
Mpstat: Handling Related statistics
Mpstat [- p { CPU | All } ] [ -v ] [ interval [ Count ] ]
View all CPU statistics, once every 2 seconds
- CPU:CPU number
- %user: The percentage of CPU time that is consumed by user-level processes (applications) during the monitored interval.
- %nice: The percentage of CPU time consumed by a user-level process that has a negative nice value during the monitored interval.
- %sys: The CPU usage that is consumed by the system and the process (kernel) during the monitored time interval. This time includes the time it takes for the system to handle soft and hard interrupts.
- %iowait: The percentage of CPU idle time that waits for the hard disk I/o during the monitored interval.
- %IRQ: The percentage of time that the CPU service has been hard-interrupted during the monitored time interval.
- %soft: The percentage of time that the CPU service has been soft-interrupted during the monitored time interval.
- %idle: The percentage of time that the CPU is idle during the monitored interval, excluding the time it takes to wait for the disk IO request.
CPU Scheduler Run queue
Role: Monitoring the CPU Scheduler run queue is used to tell if the system is full load.
Run queues: Lightweight processes that are ready to run and are waiting for available CPUs.
If the number of lightweight processes that are ready to run exceeds the limit that the system can handle, the run queue can be very long. When the system is running a queue equal to the number of virtual machine processors, the user does not noticeably experience performance degradation. (The virtual processor is the number of system hardware threads.) Runtime.availableprocessors () return value). The system responds very slowly when the run queue length reaches 4 times times or more of virtual processing.
guiding principle : If a long time, the length of the running queue has been more than 1 time times the number of virtual processors, it is important to pay attention to, if a long time, the running queue length reached 3-4 times the number of virtual processors or higher, need immediate attention or take action.
How to Solve
- Increase the CPU, share the load or reduce the processor load and fundamentally solve it.
- Analyze the applications running in the system to improve CPU utilization. Solve algorithm and data structure efficiency
On-line Vmstat 1 observing CPU queue condition
Procs
- r: Number of processes waiting in the run queue
- B: Number of processes waiting on Io
Mpstat view CPU count and CPU usage, system load is slightly higher
CPU-related monitoring and introduction.
Reference:
Http://www.ha97.com/4512.html
Http://linuxcommand.org/man_pages/vmstat8.html
Operating System performance monitoring-CPU usage