0

I use ffmpeg to transcode H265 video to H264 stream. The computer seems over capacity while pulling video from two cameras.

enter image description here

The machine is equipped with a 8-core i7-7700T. My question is, shall I use CPU utilization (460.7%, 331.7%) or load average to evaluate CPU requirement for the transcoding task.

xrfang
  • 185
  • 1
  • 1
  • 10

2 Answers2

0

Load average show the number of processes run and wait in interval of 1,5 and 15 minutes (in 5 seconds frame)

CPU utilization give you the processors usage for particular process. Which is more meaningful in your case. You can sum this value for all ffmpeg processes.

If you want to get CPU utilization for entire system in specific moment you can use command like:

vmstat 1 2

(get the second line as first is for average from start of the system)

Romeo Ninov
  • 5,263
  • 4
  • 20
  • 26
0

You should use load average to evaluate CPU requirement.

To interpret CPU usage and Load Average numbers you should take into account

  • total number of physical cores in a system (all CPUs)
  • is HyperThreading enabled
  • in Linux Load Average also includes processes in uninterruptible sleep state waiting for I/O
  • CPU usage and Load Average numbers interpretation depends on number of logical cores
  • you should check per core CPU statistics to be more accurate. In top press '1' for per core stat and 't' to turn graph bars.

i7-7700T have 4 physical cores, and with HT enabled 8 logical cores https://ark.intel.com/content/www/us/en/ark/products/97122/intel-core-i77700t-processor-8m-cache-up-to-3-80-ghz.html

CPU usage, %
show utilization - percent of time when CPU is not idle and execute tasks scheduled by OS scheduler.

Each core may used up to 100% so max usage capacity of 8 cores is 800%.

So two ffmpeg processes utilize all 8 cores at 460.7% + 331.7% = 792.4%.

Whole CPU stat in this line

%Cpu(s):  19.9 us,  0.7 sy,  78.1 ni, 1.1 id,  0.0 wa,  0.0 hi,  0.1 si,  0.0 st

Here 19.9% of user space time + 78.1% of nice time = 98% of CPU usage by userspace program.

So CPU cores are busy at 98% by all of userspace processes with 79,2% executing two ffmpeg processes.

Because transcoding is a CPU bound task, you will almost always have close to 100% utilization on any CPU.

Load Average
is an average, over some period, number of threads executed + number of threads waiting to be executed.

One core execute one thread at a time slice.
8 cores can execute 8 threads at a time slice.

System overloaded if Load Average > number of logical cores.
This means the OS scheduler cannot allocate the next time slice to some threads due to the busy cores and puts them in a run queue to wait for execution.
Second number in Load Average = 25.65 on system with 8 cores means:

  • in average 8 threads executed during last 5 minutes
  • in average 17.65 threads waits in run-queue during last 5 minutes

So system overloaded on 17.65/8*100=220.6%.

gapsf
  • 846
  • 1
  • 6
  • 12
  • I think CPU utilization might be more appropriate, as if a thread is waiting for I/O, it does not use CPU resource, but is still counted in load average, right? In case of rtsp transcoding, although it is CPU bound, network I/O is still a factor which may pump up load average. I calculated total CPU usage of ffmpeg according to [this post](https://www.baeldung.com/linux/total-process-cpu-usage), they uses about 400%~650% of CPU, which is about 6 out of 8 cors on i7-7700. – xrfang Aug 04 '22 at 00:28