-Cpu load and performance testing cpu utilization

Outline

Do stress tests, we often focus on two indicators, CPU utilization and CPU load

  Linux, the process is divided into three states:

  •   Blocked processes blocked process

  •   Runnable process runnable processes

  •   Running processes running process

  When the process is blocked, the process will wait for I / O device data or system calls.

  When the process is runnable state, it is in a run queue, and other runnable processes compete for CPU

 

CPU usage

CPU utilization refers to the percentage of CPU during program run real-time occupation, which is the CPU usage statistics for a period of time.

By this indicator can be seen in the case of a certain period of time the CPU is occupied

 

CPU load (load) 

  It refers to the total number of running (running) and ready to run (runnable) process, which is a task queue waiting to be processed

load-average 

  It refers to is run within a specific time queue average number of processes (running or waiting to run on the CPU) of .

  Linux top command in the middle is the most recent one minute, the average load of 5 minutes and 15 minutes system

  If a process meets the following conditions, it will be located in the run queue

  - it is not waiting for the results of I / O operations

  - It does not take the initiative to enter the wait state (that is, no call wait)

  - is not stopped

 

Computing cpu load

  The number of CPU and the number of CPU cores will affect the CPU load, because the task is ultimately to be assigned to the CPU core to handle.

  Two CPU better than a good CPU, dual-core better than the single-core. Thus, the difference in CPU performance removed, CPU load is calculated based on the number of cores.

  "How many cores, there are that many load". The load of 1.00 mononuclear, dinuclear load of 2.00. And so on.

 

Illustrates cpu load

 

We all have to take the elevator to take the elevator. Assuming that an elevator can stand 10 people, and that when 1-10 people take the elevator, the elevator can be considered load of <1;
just 10 when, load = 1;
more than 10 people when, load> 1;
if there are 15 individuals to take the elevator, that is to have 10 people directly on the roller coaster, five others have to wait.
At this time, the elevator load = 15/10 = 1.5
In other words, the current full load operation a system load of 1.5, and also corresponding to 50% of full load request waiting

 

For the critical value of load average, the industry there are two judgments based on

load average <= cpu核数 * 0.7

load average <= cpu核数 - 1

 

Why high case Load, low CPU usage?

  Still take an example to illustrate the elevator. Suppose a total of 20 people to take the elevator. Elevator run for 5 minutes. Between the two runs, the first batch of 10 people down, the second batch of 10 people, elevators and other people come in, plus closing time period should be 3 minutes. In this case the elevator utilization rate is about 50%. The roller coaster of load is 2. Corresponds to our CPU, when the (thread) excessive running process, frequent context switches consumes a lot of CPU time, resulting in a real operation with less CPU time slice (low CPU usage), there are many processes waiting to be run (high Load). 

 

Cpu utilization and load value level is not necessarily related directly

  We do generally believed that when the pressure measured CPU utilization and Load values ​​are higher proportional relationship, both Load value, the higher CPU utilization.

But in fact sometimes Load high, CPU utilization, lower than the (multi-core more uneven distribution situation may occur).

  Load is because the task queue waiting to be processed, when your application while waiting for the return synchronization message processing, CPU time slice or will be assigned to these threads.

And those who really need CPU thread, but had to temporarily give up work at a later time slot is not suspended.

  CPU利用率高也并不意味着负载就一定大,可能这个任务是一个CPU密集型的。CPU低利用率的情况下也会有高Load Average的情况。当CPU分配时间

片以后,是否使用完全取决于使用者,因此完全可能出现低利用率高Load Average的情况。

  因此在程序设计的时候要考虑如何利用好CPU的这个资源,如何均匀的将压力分摊到各个CPU 上(有时候一个线程在不断循环,导致单个CPU负荷很高)

 

再举例

  公共电话亭里有一个人在打电话,后面有四个人在等待,每人限定使用电话一分钟。若有人一分钟之内没有打完电话,只能挂掉电话去排队,等待下一

轮。公共电话在就相当于CPU,而正在打电话或等待打电话的人就相当于任务数。

  在电话亭使用过程中,肯定会有人打完电话走掉,有人没有打完电话而选择重新排队,更会有新增的人在这儿排队。人数的变化就相当于任务数的增减。

为了统计平均负载情况,我们5秒钟统计一次人数,并在第1、5、15分钟的时候对统计情况取平均值,从而形成第1、5、15分钟的平均负载。

  有的人拿起电话就打,打满1分钟,有的人可能前三十秒在找号码,或者犹豫要不要打,后三十秒才真正开始打。如果把电话看作CPU,人数看作任务,

我们可以说前一个人(任务)的CPU利用率高,后一个人(任务)的CPU利用率低。当然, CPU并不会在前三十秒工作,后三十秒歇着,它一直在处于load

状态。

  有的程序涉及到大量的计算,所以CPU利用率就高,而有的程序牵涉到计算的部分很少,CPU利用率自然就低。但无论CPU的利用率是高是低,跟后面有多少任务在排队没有必然关系(cpu利用率和load没有必然关系)。

 

  在Linux系统中,可以通过命令看到系统平均负载load-average的输出


  uptime

 

 

 

  top

 

 

  saq -q

runq-sz:运行队列的长度(等待运行的进程数)

plist-sz:进程列表中进程(processes)和线程(threads)的数量

ldavg-1:最后1分钟的系统平均负载(Systemload average)

ldavg-5:过去5分钟的系统平均负载

ldavg-15:过去15分钟的系统平均负载

 

Guess you like

Origin www.cnblogs.com/Zfc-Cjk/p/11528936.html