Analysis of CPU consumption in Linux environment

Source: Internet
Author: User
Tags switches

In Linux systems, the CPU is primarily used for interrupt, kernel, and user process task handling, with priority being interrupt > Kernel > User process. In the CPU consumption analysis, we also often encounter the following several concepts.

    • Context Switches

Each CPU can execute only one thread at a time, and Linux threads are preemptive-scheduled. That is, each thread allocates a certain amount of execution time, when the execution time is reached, there is an IO block in the thread, or when a high-priority thread is executed, Linux switches the executing thread, stores the execution state of the current thread at the time of the switchover, and restores the state of the thread to be executed, a process known as context switching. In Java applications, for file IO operations, network IO operations, lock waits, or thread sleep, the current thread goes into a blocking or hibernation state, triggering a context switch. Too much context switching causes the kernel to occupy more CPU usage, which slows down the response of the application.

    • Run queue

Each CPU maintains a running thread queue, assuming that 16 threads are started in a 8-core Cpu,java application, and that if all 16 threads are in a running state, there will be 2 threads in each CPU's running queue if the average is allocated. Usually, the load of the system is mainly determined by the CPU's running queue, assuming the above condition is maintained for 1 minutes, then the system load is 2 in 1 minutes. In general, the larger the run queue value, the longer the thread will take to complete.

    • Utilization

CPU utilization is a percentage of CPU usage in user processes, cores, interrupt processing, IO waits, and idle 5 parts, and these 5 values are key metrics used to analyze CPU consumption.

In Linux we can see the CPU consumption of the process through the top or PIDSTAT commands.

    1. Top

In the output of the top command, US represents the percentage of user process processing, SY represents the percentage of kernel threading, and NI represents the percentage of tasks that have been prioritized by the Nice command, the ID represents the percentage of CPU idle time, and WA indicates that it waits for the percent of IO to be accounted for during execution. Ratio, HI indicates the percentage of hardware interrupts, and SI represents the percentage of software outages.

2. Pidstat

Pidstat is a tool in SYSSTAT (installed under Ubuntu: sudo apt-get install SYSSTAT)

When CPU consumption is severe, it is mainly reflected in the value of us, sy, WA or Hi, and the value of WA is the IO waiting cause. For Java applications, CPU consumption is mainly manifested in us, SY

Two values are high.

Analysis of CPU consumption in Linux environment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.